Using Java technology to implement business logic in Cocoon

xiaoxiao2021-03-06  65

source:

http://www.linuxforum.net/forum/printthread.php?cat=387301&type=post.com=java/prin

If you have a understanding of Apache Cocoon or to be involved, you may be better to use Java in CoCoon.

Realization of specific logic has doubtful. This article will show you how to use XSP (EXTENSIBLE SERVER PAGE)

And Action. There is also an example and design principles.

You may have heard some sound from Apache about Cocoon. Now, after three years of development,

Cocoon has gradually converted from a simple implementation XSL (Extensible Stylesheet Language)

Servlet grows into a full web application framework.

CoCoon is developed with Java, which is generally used as a servlet container like Tomcat as a servlet.

In this article, we will introduce two ways to use Java to implement commercial logic in Cocoon-based applications.

First, let's take a look at Cocoon.

CoCoon officially defined is an XML publishing engine, we can understand that cocoon is used to generate, convert, and process

And the framework of output data. It can also be understood that Cocoon is a different processing from a variety of data sources to apply different processing, the most

The machine after the data is output in the desired format.

We can also define Cocoon as a data stream machine. That is to say, when you use Cocoon, you define the path of the data.

Trail or flow to generate a page of web applications.

Below is some of COCOON's main basic principles:

1. Cocoon handles all the data as the SAX (Simple API for XML) event, any non-XML data must

Transfer into an XML description.

2, components that generate SAX events are responsible for processing input data

3. The serializer is responsible for processing output data to output data to the client (browser, file, etc.).

4. Developer combination generators, serializer, and other components constitute a pipe. All pipes are in a map called site map

Definition in the file.

5, match the pipe through the URI (Uniform Resource Identifier), but the URI is detached from the physical resource.

Point 5, you need to explain:

For traditional Web Server, the URI is generally mapped to physical resources.

For example, this URI

http://localhost/index.html will map to INDEX.HTML in Apache Server

HTML file.

In Cocoon, URIS and physical resources may be without any absolute relationship. You can help the URI you can

Help users browse your site better. Finally, you can organize your files to make it easy to manage and maintain.

In order to better understand the Cocoon's processing model, you can see a simple pipe.

The following example defines a page called INDEX.html. This pipe is located in the SiteMap.xmap site map:

This pipe has three steps:

The first is a generator component FileGenerator reads data from the XML file "content / mainfile.xml".

(FileGenerator actually has already defined in the map in advance, you can reference all in .cocoon through the "Type" property

Pipe components are referenced by their Type properties. )

The conversion is then performed, and the converter Traxtransformer applies the XSL StyleSheet to the introduced data.

Finally, the sequencer HTMLSerializer writes the data to the client's browser.

You may be confused, what is in connection with Java development?

We divide Cocoon's application into three parts:

1, data collection layer DATA Collection (Generation)

2, data processing and conversion layer Data Processing & Transforming

3. Output layer Data Output (Serialization)

Then, Java development is very important in Cocoon's processing conversion layer. Cocoon's conversion and processing layer are cocoon

The core of the application, through this layer of processing, logical applications, logical applications, you can get the desired output.

In Cocoon, you can have the following four ways to implement logic:

1. Use the Transformer component: They convert the incoming data according to the rules you give. Classic example

It is traxtransformer.

2. Select different components to make correct processing through different requests, session, and uri.

3, use an existing or you implement the Action.

4. Use XSP that mixed Java code and content.

This article introduces the last two methods: XSP and Action. The development of XSP and Action is in the servlet context.

Specifically, two components (actually all components) have access to Request, Response, Session, and

Context object. In some ways, a lot of logic you want to achieve will interact with these objects.

XSP

XSP is the innovation of the Cocoon project. You can compare it with JSP because they are mixed logic and content and JSP

Taglib and XSP logicsheet are also very similar.

XSP is located at the starting point of the pipe, in fact it is converted into a generator (Generator) to give the rest of the components in the pipe.

Data.

Let us look at this called Sample1.xsp simple example:

Date now = new date ();

String msg = "boo!";

Welcome to Cocoon </ Title></p> <p><paragraph></p> <p>This is an xsp. You can see how We it Contain Both Logic</p> <p>(Inside the <xsp: logic> tags) and content. in The Logic Block</p> <p>Above, We created a date Object whose value is <xsp: expr> now </ xsp: expr>.</p> <p>OH, WE Also Had a Special Message for you: <xsp: expr> msg </ xsp: expr> </ paragraph></p> <p></ content></p> <p></ xsp: Page></p> <p>First pay attention to the root mark of this document is <XSP: page>.</p> <p><xsp: page language = "java" xmlns: xsp = "http://apache.org/xsp"></p> <p>This tag defines the XSP's Language (can be Java or JavaScript) and the Namespace for the logical order for use.</p> <p>Then we define the <xsp: Logic> block of two Java variables.</p> <p>These <Xsp: Logic> blocks can have multiple, which can appear anywhere in your hope, and can contain various Java code.</p> <p>Finally, our own content, starting from the user's own follow-up, in the above example is <Content>. In the content part,</p> <p>We can get the variables defined in front with <xsp: expr>.</p> <p>Remember, an XSP is actually a generator generator. CoCoon converts it to the Java source file and compile it.</p> <p>(If you want to see the Java source file converted into XSP, go to your servlet container's work path. For example,</p> <p>If you use Tomcat 4.0.4, the path is below:</p> <p>$ Catalina_Home / Work / Standalone / localhost / cocoon / cocoon-files / org / apache / cocoon / www.)</p> <p>XML data generated after XSP execution is passed to the remaining components of the pipe.</p> <p>Look at this pipeline example:</p> <p><map: pipeline match = "*. xsp"></p> <p><map: generate type = "serverpages" src = "Examples / {1} .xsp" /></p> <p><map: serialize type = "xml" /></p> <p></ map: pipeline></p> <p>Here, we use a specified generator ServerPagesGenerator to handle our simple XSP. Back to customers</p> <p>Non-modified XML.</p> <p>TEAPERARATION The specifically {1} variable reference is used: it instead of the value indicated by the wildcard starting at the beginning of the pipe. That is to say,</p> <p>If we open Sample1.xsp in our web app in your browser, the value of {1} is Sample1.</p> <p>Remember, just like most Cocoon components, XSP accesses the Request, Response, Session, and Context objects. These ones</p> <p>Objects are actually HTTPSERVLETREQUEST, HTTPSERVLETRESPONSE, HTTPSESSION, and</p> <p>HTTPSERVLETCONTEXT package, Cocoon official version provides a large number of methods for accessing these objects.</p> <p>XSP is especially useful when reading data from the database.</p> <p>Database data naturally organizes rows and columns, so database data is easy to convert to XML. However, JDBC</p> <p>(Java Database Connectivity) There is no connection to XML conversion.</p> <p>XSP allows us to be easy when reading data, thank you ESQL logic. ESQL logic in addition to hidden</p> <p>JDBC code also allows rows and columns to be placed in a specific tag. At the same time, ESQL logic can also perform nested query</p> <p>And execute the update command.</p> <p>Below, we will give an example of an XSP application: If we want to store some Cocoon's resources (name and URL) to the database.</p> <p>First, we define the data sheet where the resource is stored, then when the user searches by keyword, we use XSP to find the corresponding</p> <p>The line is displayed to the user.</p> <p>Subsequently, we build a form to add new columns.</p> <p>The definitions and insertions of the table are shown below. The database we used here is mysql, if you are using other</p> <p>Database, pay attention to do the corresponding changes. In this example, you must have a configuration database connection pool.</p> <p>The surface structure is as follows:</p> <p>Use test;</p> <p>Create Table Resources</p> <p>Resourceurl Varchar (255) Not Null,</p> <p>ResourceName VARCHAR (64) Not NULL</p> <p>);</p> <p>Insert some resource data:</p> <p>Insert Into Resources Values</p> <p>('http://xml.apache.org/cocoon', 'Cocoon Home Page');</p> <p>Insert Into Resources Values</p> <p>('http://www.galatea.com/flashguides/cocoon-tips-2.xml', 'Cocoon 2.0 Tips and Tricks';</p> <p>After the table is built and COCOON is also correct, we can write the following XSP example:</p> <p><? XML Version = "1.0"?></p> <p><xsp: page language = "java"</p> <p>XMLns: Xsp = "http://apache.org/xsp"</p> <p>XMLns: esql = "http://apache.org/cocoon/sql/v2"></p> <p><xsp: logic></p> <p>String Keyword = Request.GetParameter ("Value");</p> <p></ xsp: logic></p> <p><Content></p> <p><Title> Search Results </ Title></p> <p><ESQL: Connection></p> <p><ESQL: Pool> Resources </ esql: pool></p> <p><ESQL: Execute-Query></p> <p><ESQL: Query></p> <p>Select * from resources</p> <p>WHERE ResourceName Like '% <xsp: expr> keyword </ xsp: expr>%'</p> <p></ esql: query></p> <p><esql: results></p> <p><resources></p> <p><ESQL: Row-Results></p> <p><resource></p> <p><esql: get-colorns /></p> <p></ resource></p> <p></ esql: row-results></p> <p></ resources></p> <p></ esql: results></p> <p></ esql: Execute-Query></p> <p></ ESQL: Connection></p> <p></ content></p> <p></ xsp: Page></p> <p>Note Namespace (Namespace) declared in the <XSP: Page> tag. At any time, when using logical orders in XSP,</p> <p>You must declare its namespace. You can find logical orders in Web-INF / COCOON.XCONF under the Cocoon WebApp path. The declaration of the XSP namespace is to indicate that this is an XSP logic.</p> <p>In fact, all XSPs are at least to implement XSP logic orders. The logical order before XSP is converted into a Java source file</p> <p>(I actually only XSL files) will be switched to Java code first. Therefore, all of the examples in the above example</p> <p>The ESQL tag will be converted to the JDBC code we are familiar with. But not all tags can become JDBC code,</p> <p>Note the <ESQL: Pool> block in the example above, which involves the database defined in the web-INF / COCOON.XCONF file</p> <p>connection pool. The connection pool used in the above program is called "resources", of course you can use the definition you like.</p> <p>Note that we use the <resources> this label here to package the result set and the data per line is placed in <resource></p> <p>Sign. This way we can easily write a style sheet to convert XML into other browsers to understand. we do not have</p> <p>Define any labels for the list of tables, by using <ESQL: Get-Column />, CoCoon will put the value of each column to the corresponding</p> <p>The tag defined by the column name.</p> <p>Now, let me pay attention to the SQL query statement in the example. As you can see, this SQL is dynamically generated. As a user</p> <p>After submitting data from gets or posts to this XSP, at the top of XSP, we assume the value of the Request parameter to</p> <p>The keyword variable and then constitute a SQL statement according to Keyword.</p> <p>Since this example is simple, let's turn it into a point, join the Email function, you can provide the email address after the user,</p> <p>Send the query results to the user.</p> <p>XSP examples are as follows:</p> <p><? XML Version = "1.0"?></p> <p><xsp: page language = "java"</p> <p>XMLns: Xsp = "http://apache.org/xsp"</p> <p>XMLns: ESQL = "http://apache.org/cocoon/sql/v2"</p> <p>XMLns: sendmail = "http://apache.org/cocoon/sendmail/1.0"</p> <p>XMLns: Xsp-request = "http://apache.org/xsp/request/2.0"</p> <p>></p> <p><Content></p> <p><xsp: logic></p> <p>String keyword = <xsp-request: get-parameter name = "value" /></p> <p>String emailddr = <xsp-request: get-parameter name = "email" /></p> <p>String emailbody = "";</p> <p></ xsp: logic></p> <p><Title> Search Results </ Title></p> <p><ESQL: Connection></p> <p><ESQL: Pool> Resources </ esql: pool></p> <p><ESQL: Execute-Query></p> <p><ESQL: Query></p> <p>Select * from resources where resourceename like</p> <p>'% <xsp: expr> keyword </ xsp: expr>%' Order by ResourceName </ esql: query></p> <p><esql: results></p> <p><resources></p> <p><ESQL: Row-Results></p> <p><resource></p> <p><xsp: logic></p> <p>EmailBody = <esql: get-string column = "resourceEName" /></p> <p>EmailBody = ", <esql: get-string column =" resourceURL "/> " / n ";</p> <p></ xsp: logic></p> <p><esql: get-colorns /></p> <p></ resource></p> <p></ esql: row-results></p> <p></ resources></p> <p></ esql: results></p> <p></ esql: Execute-Query></p> <p></ ESQL: Connection></p> <p><xsp: logic></p> <p>IF (EmailAddr! = null) {</p> <p><sendmail: send-mail></p> <p><Sendmail: Charset> ISO-8859-1 </ sendmail: charset></p> <p><sendmail: SMTPHOST> my_smtp_host </ sendmail: SMTPHOST></p> <p><sendmail: from> my_from_address </ sendmail: from></p> <p><sendmail: to> <xsp: expr> emailddr </ xsp: expr> </ sendmail: to></p> <p><Sendmail: Subject> Cocoon Search Results </ sendmail: Subject></p> <p><sendmail: body> <xsp: expr> emailbody </ xsp: expr> </ sendmail: body></p> <p></ sendmail: send-mail></p> <p>}</p> <p></ xsp: logic></p> <p></ content></p> <p></ xsp: Page></p> <p>Several labels from Sendmail logic let us have the ability to send email. In this example, we will query results</p> <p>Each row is added to assign the EmailBody variable as the body of the mail. When the user provides an email address via the request parameter,</p> <p>We can send email. Of course, this requires you set a good SMTP server and from address in advance.</p> <p>Cocoon knows the label in the Sendmail namespace based on Sendmail logic, because this namespace already</p> <p>It has declared in the <XSP: Page> tag. To view the declaration in the example, you will see the namespace of XSP-Request.</p> <p>The XSP-Request logic single provides packages for the Request common method. Although directly accessed the Request object directly in XSP and</p> <p>There is no functionality that uses XSP-Request logic orders, but theoretically use Logicsheet labels</p> <p>The Java code is more beautiful.</p> <p>Before running this example, you must first set the sendmail logic in the COCOON.XCONF file, Cocoon's configuration</p> <p>The files are all under the web-inf directory of the Web Application. Open the cocoon.xconf file with your familiar editor,</p> <p>Find <target-language name = "java"> tab. In this block, you will find the definition of all other logical orders. Add the following content after the last logical order (SOAP logic list):</p> <p><Builtin-Logicsheet></p> <p><parameter name = "prefix" value = "mail" /></p> <p><parameter name = "URI" value = "http://apache.org/cocoon/sendmail/1.0" /></p> <p><parameter name = "href"</p> <p>Value = "resource: //org/apache/cocoon/components/language/markup/xsp/java/sendmail.xsl" /></p> <p></ builtin-logicsheet></p> <p>This definition will http: //apache.org.cocoon/sendmail/1.0 namespace and already included in Cocoon Jar</p> <p>Sendmail.xsl style sheet is united.</p> <p>To use the features of the Sendmail logic, Cocoon must have mail.jar and activation.jar. Two JARs.</p> <p>If you use Server is Tomcat4.x, then they are located in $ Catalina_Home / Common / Lib.</p> <p>Actions</p> <p>The Action function is very powerful, you can put it in any place it in the pipe. Action can be considered a small self-contained machine,</p> <p>It gets some input data, do some processing, and then returns the HashMap object. Unnenrators in Cocoon,</p> <p>Transformers, Serializers Components, Action does not do anything about the actual XML content, mainly in the pipeline</p> <p>Implement some logic.</p> <p>Learning Action includes some understanding of the pipeline parameters, and sometimes the components of the pipe must communicate data. Of course, XML content</p> <p>The SAX event passes; however, what we said is the value required for the function of the pipeline assembly itself.</p> <p>There are two types of pipeline parameters: input and output. The Input parameter is one or more of the back of the component declaration.</p> <p><map: parameter> tag is defined. They provide one or more values ​​for components to affect their operations.</p> <p>These two components can provide an accessible Output variable for their back components.</p> <p>These Output parameters are placed in the HashMap object, can be referenced by the KEY name (such as {1}).</p> <p>All pipes have at least a HashMap provided by Matcher from the beginning of the pipe. We use this in the pipeline</p> <p>HashMap object, use {1} to get the value of Key 1 in HashMap.</p> <p>CoCoon itself contains some built-in Action. One of them is to rely on the database to identify the user's action. when we</p> <p>To protect some of the pages in Cocoon, you can store the user ID and password when you are allowed to access users.</p> <p>Curry, then use DatabaseAuthenticationAction to do login confirmation.</p> <p>This DatabaseAuthenticationAction requires us to provide an XML description file to explain which table you want to use and</p> <p>Some columns. Here is an example of this description file:</p> <p><? XML Version = "1.0" encoding = "UTF-8"?></p> <p><auth-descriptor></p> <p><Connection> Resources </ connection> <Table Name = "Uses"></p> <p><select dbcol = "user_name" request-param = "userid" to-session = "userid" /></p> <p><select dbcol = "user_password" request-param = "userpwd" /></p> <p></ TABLE></p> <p></ auth-descriptor></p> <p>Above this file Description User Certification Action will use the Resources connection pool and user table, the UserId parameter submitted by the request</p> <p>And the UserPwd parameter will compare with user_name and user_password columns in the USER table, if successful confirmation,</p> <p>Number UserId is written in the session.</p> <p>When you use an Action in your pipe, it must first in the <map: components> block in the site map.</p> <p>Definition in the <map: actions> block. as follows:</p> <p><map: company</p> <p><! - all other component definitions go here -></p> <p><map: actions></p> <p><map: action name = "authenticator"</p> <p>SRC = "org.apache.cocoon.acting.DatabaseAuthenticatorAction" /></p> <p><! - Other Actions Definitions Go Here -></p> <p></ map: actions></p> <p></ map: companyNPONENTS></p> <p>Once defined, you can use this Action to be responsible for the area we have to protect. Below is the area to be protected</p> <p>Three pipes:</p> <p><map: match pattern = "protected / login.html"></p> <p><map: read mime-type = "text / html" src = "secret / login.html" /></p> <p></ map: match></p> <p><map: match pattern = "protected / login"></p> <p><map: act type = "automator"></p> <p><map: parameter name = "descriptor" value = "secret / auth-info.xml" /></p> <p><map: redirect-to uri = "index.html" /></p> <p></ map: ACT></p> <p><map: redirect-to uri = "login.html" /></p> <p></ map: match></p> <p><map: match pattern = "protected / *"></p> <p><map: match type = "sessionState" pattern = "*"></p> <p><map: parameter name = "attribute-name" value = "userid" /></p> <p><map: match pattern = "protected / *. html"> <map: read mime-type = "text / html" src = "secret / *. html" /></p> <p></ map: match></p> <p><map: match pattern = "protected / *. xsp"></p> <p><map: generate type = "serverpages" src = "secret / {1} .xsp" /></p> <p><map: serialize type = "xml" /></p> <p></ map: match></p> <p></ map: match></p> <p><map: redirect-to uri = "login.html" /></p> <p></ map: match></p> <p>The first pipeline provides a login form, which is an HTML file and does not require conversion. Second pipe processing</p> <p>The actual login action submitted from Login.html. The third is to deal with the content we have to protect.</p> <p>Let's make a detailed discussion:</p> <p>DatabaseAuthenticationAction relies on the description file to verify the login. But how do we know if verification?</p> <p>Success? For Action, if they return a valid HashMap, then in the <map: ACT> block will be</p> <p>Row. If the NULL value is returned, the part below will be executed. That is to say, according to the definition of the above pipeline, we</p> <p>There are two possible outcomes, that is, if the authentication is passed, we can reach the protected area, if the failure will return</p> <p>Go to the Login page.</p> <p>In protected / * pipes, there are several nesting Matcher, the second type is sessionState, this Matcher</p> <p>In fact, WildcardSessionTtributeMatcher is used here to read the value of the userid in the session.</p> <p>In this example, we know that DatabaseAuthenticationAction sets a session genus called UserID.</p> <p>Sex, we determine if the user logs in successfully, if it does not exist, turn to the Login page.</p> <p>There is already a DatabaseAddAction in Cocoon, but in order to insert data, but in order to better understand Action, we</p> <p>Write your own action to insert a new resource record into the resources table.</p> <p>We imagine that you have written an HTML page that can be used to POST two variables Name and URL to the pipe. our</p> <p>Action will retrieve the Name and URL parameters from the Request object, insert it into the table, and finally return a HashMap object.</p> <p>Below is the program code:</p> <p>Package test;</p> <p>Import org.apache.avalon.excalibur.datasource.DataSourceComponent;</p> <p>Import org.apache.avalon.framework.component.componentexception;</p> <p>Import org.apache.avalon.framework.component.componentmanager;</p> <p>Import org.apache.avalon.framework.component.componentselector;</p> <p>Import org.apache.avalon.framework.parameters.Parameters;</p> <p>Import org.apache.avalon.framework.thread.threadsafe;</p> <p>Import org.apache.avalon.framework.component.composable;</p> <p>Import org.apache.Avalon.framework.activity.disposable;</p> <p>Import org.apache.cocoon.environment.ObjectModelhelper;</p> <p>Import org.apache.cocoon.environment.Redirector;</p> <p>Import org.apache.cocoon.environment.Request;</p> <p>Import org.apache.cocoon.environment.Session;</p> <p>Import org.apache.cocoon.environment.sources;</p> <p>Import org.apache.cocoon.acting.Abstract;</p> <p>Import java.sql.connection;</p> <p>Import java.sql.statement;</p> <p>Import java.sql.sqlexception;</p> <p>Import java.util.hashmap;</p> <p>Import java.util.map;</p> <p>Public Class AddResourceAction Extends AbstractAction</p> <p>Implements Threadsafe, Composable, Disposable</p> <p>{</p> <p>Protected componentSelector dbselector;</p> <p>Protected ComponentManager Manager;</p> <p>Public void compose (ComponentManager Manager).</p> <p>THIS.DBSELECTOR =</p> <p>(ComponentSelector) Manager.lookup (DataSourceComponent.Role "Selector");</p> <p>}</p> <p>Protected final DataSourceComponent GetDataSource (String pool)</p> <p>Throws componentexception {</p> <p>Return (DataSourceComponent) this.dbselector.select (pool);</p> <p>}</p> <p>Public Map Act (Redirector Redirector, SourceResolver Resolver,</p> <p>Map ObjectModel, String</p> <p>Source, Parameters Param)</p> <p>Throws Exception</p> <p>{</p> <p>Request Req = ObjectModelhelper.getRequest (ObjectModel);</p> <p>Session SES = Req.getSession (TRUE);</p> <p>String poolname = param.getParameter ("pool");</p> <p>String resourceEName = Req.getParameter ("name");</p> <p>String resourceURL = Req.getParameter ("URL");</p> <p>IF (poolname == null) {</p> <p>GetLogger (). Error ("Missing a pool name");</p> <p>Return NULL;</p> <p>}</p> <p>IF (resourceename == null || resourceURL == null) {</p> <p>GetLogger (). Error ("Missing Input Parameters"; Return NULL;</p> <p>}</p> <p>Map map = new hashmap ();</p> <p>DataSourceComponent DataSource = getDataSource (poolname);</p> <p>Connection conn = NULL;</p> <p>Boolean status = false;</p> <p>Try {</p> <p>CONN = DataSource.getConnection ();</p> <p>Statement Stmt = conn.createstatement ();</p> <p>String cmd = "INSERT INTO Resources VALUES ('" </p> <p>ResourceName "','" </p> <p>ResourceURL "')"</p> <p>Stmt.executeUpdate (cmd);</p> <p>Map.put ("Resource-name", resourceename;</p> <p>Map.put ("Resource-URL", ResourceURL;</p> <p>GetLogger (). Debug ("Resources Insert Completed By User" </p> <p>SES.GETID ());</p> <p>STATUS = TRUE;</p> <p>Stmt.close ();</p> <p>} catch (exception e) {</p> <p>GetLogger (). Error ("Stmt Failed:", E);</p> <p>} finally {</p> <p>Try {</p> <p>IF (conn! = null) conn.close ();</p> <p>} catch (sqlexception sqe) {</p> <p>GetLogger (). Warn ("Error Closing The Datasource", SQE</p> <p>}</p> <p>}</p> <p>IF (! status) Return NULL;</p> <p>Return (Map);</p> <p>}</p> <p>Public void dispose () {</p> <p>This.manager.release (DBSELector);</p> <p>}</p> <p>}</p> <p>There are a lot of things that require digestion, especially if you are not familiar with Cocoon's structure. Let's step by step.</p> <p>First, the main method of COCOON Action is ACT (), when Cocoon will call this method when using an action in the pipe.</p> <p>In this example, ACT () gets the request parameter, gets the database connection from the connection pool, performs insert, then populate</p> <p>Hashmap object and return it.</p> <p>The beginning of the ACT method is to get the request object from the ObjectModelhelper component, then get two parameters. This one</p> <p>Action requires another parameter, pool; it will tell us which connection pool. If this parameter is not, then</p> <p>Action will return NULL and write errors to the log. With the name of the pool, we can get data from the connection pool.</p> <p>The connection of the library. Avalon's EXCALIBUR component is used to be responsible for Cocoon's connection pool. If you are not familiar with avalon, you can</p> <p>Visit here http://jakarta.apache.org/avalon/.</p> <p>Insert Statement in the code is a direct JDBC syntax. After insertion of success, the successful information will be written to the log.</p> <p>For logs, if all log information is written to your Web Application</p> <p>Web-inf / logs / sitemap.log file.</p> <p>Finally, we write two input parameters to the Map object, although they are all in the Request object, so that we do this is for the usage of the Map object.</p> <p>Look at this Action definition in the site map. We must first define the <map: company in the site map.</p> <p>Righteous this Action.</p> <p><map: company</p> <p><! - all other component definitions go here -></p> <p><map: actions></p> <p><map: action name = "authenticator"</p> <p>SRC = "org.apache.cocoon.acting.DatabaseAuthenticatorAction" /></p> <p><map: action name = "add-resource" src = "test.addResourcection"</p> <p>Logger = "sitemap.action.AddResource" /></p> <p><! - Other Actions Definitions Go Here -></p> <p></ map: actions></p> <p></ map: companyNPONENTS></p> <p>Use this Action in the pipe:</p> <p><map: match pattern = "addresource"></p> <p><map: act type = "add-resource"></p> <p><map: parameter name = "pool" value = "resources" /></p> <p><map: read mime-type = "text / html" src = "examples / confirmation.html" /></p> <p></ map: ACT></p> <p><map: read mime-type = "text / html" src = "examples / addresource.html" /></p> <p></ map: match></p> <p>It can be seen that below the <map: act> line, followed by the <map: parameter> tag to provide the "pool" parameter.</p> <p>Everything goes well, Action will return a MAP object, and the Confirmation page will be displayed.</p> <p>Open http: // localhost: 8080 / cocoon / addresource in your browser, you will see a input form.</p> <p>After the form is submitted, if the insert is successful, the Confirmation page will be displayed. If an error occurs, return it to the form again.</p> <p>page. View web-inf / logs / sitemap.log, error message tells you what errors have appeared.</p> <p>How to use XSP and ACTION?</p> <p>XSP and Action are two different ways to implement logic in Cocoon. Which one is better?</p> <p>XSP is useful in taking data or creating structured data. Action is proven to control data flow</p> <p>(Not produced or influenced data) is useful. User verification and database we see above</p> <p>The operation is two examples.</p> <p>However, there is a point in need to explain: XSP will mix logic and content. Cocoon's basic principles</p> <p>It is logical, content, and expressed separation.</p> <p>When using XSP, we offer the following suggestions:</p> <p>First, use logic orders as much as possible, and hide the Java code very well. Second, try to use Cocoon's feature, such as: When doing database, we can also use</p> <p>SqlTransformer is implemented.</p> <p>Third, in decision-making logic, use the Selector, Matcher, or Action components as possible.</p> <p>Finally, when you can't avoid inserting Java logic in your XSP, you can make <xsp: logic> small, and don't</p> <p>Distribute them into a variety of your labels.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-89611.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="89611" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.033</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'F9UN3WVdz_2FkA_2FU2ZuWCyma5Ba_2FzT_2F_2BnBSEAjY3xra5B9CdFyyes8osyWwcfw6NV21qHRHFrBmyZUNByMMxoogg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>