Tomcat6 + struts2

Source: Internet
Author: User

Recently, I have been using struts2 + extjs2.1 to learn how to do things.

For tomcat6 and struts2, briefly record it. Only memo.

1. Deploy and test struts2 on tomcat5.0.28.

When Tomcat is started, an error is reported:

-------------------
Javax. xml. Transform. transformerfactoryconfigurationerror: provider org. Apache. xalan. processor. transformerfactoryimpl not found

After searching on the Internet, it is known that a class conflict is caused.

Solution: remove the xml-apis.jar package in/common/endorsed/Under the tomcat installation path, and then start tomcat5.0.28.

 

2. struts2 runs on tomcat5.5 or a later version.

So I switched to Tomcat 6, which was never used before. After two months of use, I found that Tomcat 6 is still very good.

Go to http://www.apache.org/and download a: apache-tomcat-6.0.16.exe.

During use, it is found that some areas are different from Tomcat 5.

Problems:

1. When Tomcat 6 is started, the console displays the following similar information:

-----------------------------
Information: the Apache Tomcat native library which allows optimal performance in Production
Environments was not found on the java. Library. Path :......
-----------------------------

This is the event information of the aprlifecyclelistener listener, which is located in atat_home/CONF/server. xml:
... <Listener classname = "org. Apache. Catalina. Core. aprlifecyclelistener

We recommend that you use Apache apr.

:

Http://tomcat.heanet.ie/native/1.1.10/binaries/win32/tcnative-1.dll

Put the file in the bin directory of Tomcat as instructed

Restart Tomcat 6.

Http://tomcat.apache.org/tomcat-6.0-doc/apr.html for details

 

2. Database Connection Pool Configuration:
 
Because Tomcat 6 does not have the same admin module as Tomcat 4/5, Tomcat web server administration tool cannot be enabled to configure database connection pools and other information.

The manual configuration is as follows:

1) copy the JAR file of the database driver to the Lib folder;

2) create a/Catalina/localhost path folder under the tomcat_home/CONF/folder by referring to the tomcat5.0 method;

3) In the/localhost/folder, create an XML file corresponding to the Web application name, such as test. xml;

4) edit the test. xml file as follows in the configuration of the tomcat5.0 connection pool:

-----------------------------
<? XML version = '1. 0' encoding = 'utf-8'?>
<Context docbase = "test" Path = "/test" privileged = "true" reloadable = "true">
<Resource Name = "JDBC/test"
Auth = "Container"
Type = "javax. SQL. datasource"
Driverclassname = "oracle. JDBC. Driver. oracledriver"
Url = "JDBC: oracle: thin: @ 127.0.0.1: 1521: orcl"
Username = "system"
Password = "manager"
Maxactive = "50"
Maxidle = "10"
Maxwait = "5000" type = "codeph" text = "/codeph"/>
</Context>
-----------------------------

This configuration attribute is roughly the same as that of Tomcat 5, but it is more concise than Tomcat 5.

 

3. Test and deploy struts2:

1) You need to modify the Web. xml file and specify the filter of struts2.

2). Struts. xml and Struts. properties are deployed at the webroot/WEB-INF/classes/file level.

These two files can be stored in the src directory of the web project in eclipse.

Configure all actions in struts. xml.

Action, remember to start with "/", such:

<Result name = "success">/mainframe. jsp </result>

Struts2 form submission can be written as follows
 
<S: Form Action = "loginaction" theme = "simple" id = "loginform" method = "Post">

The theme = "simple" attribute specifies the arrangement and rendering mode of struts2 elements.

If the forwarding path is incorrectly configured or the action specified for form submission is incorrect, tomcat6 will warn:

-----------------------------
No configuration found for the specified action: 'loginaction. action' in namespace :''.
Form Action defaulting to 'action' attribute's literal value.
-----------------------------

3). Struts. properties is to borrow files in the struts-core-2.0.x.jar, formerly known as default. properties.

Rename struts. properties to the src directory of the web project.

Make the following changes:
 
Struts. locale = zh_cn

Struts. i18n. Encoding = gb2312

After modification, Struts can recognize Chinese characters.

Struts. Action. Extension = action

The default extension of struts action is. Action.

4) When Ajax calls an action, you can use the tag to reference the attribute in the action as the return value to Ajax in the returned page. For example:

-----------------------------
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8" pageencoding = "UTF-8" %>
<% @ Taglib prefix = "S" uri = "/Struts-tags" %>
<S: property value = "jsondatastring" Escape = "false"/>
-----------------------------

 

The attribute escape = "false" is very important.

When the struts2 label is used to display the result, set escape = "false" so that struts2 does not escape the string.
 

PS: Today's Olympic torch passes on Shi.

 

[End]

 

By jrq

 

2008/07/29 in Beijing

 

 

 

 

PS:

You can see another method for configuring the tomcat6 connection pool on the Internet:

-----------------

1. Modify tomcat6/CONF/context. xml and add
<Resource Name = "JDBC/test1"
Auth = "Container"
Type = "javax. SQL. datasource"
Driverclassname = "oracle. JDBC. Driver. oracledriver"
Url = "JDBC: oracle: thin: @ 127.0.0.1: 1521: orcl"
Username = "test1"
Password = "test1"
Maxactive = "100"
Maxidle = "30"
Maxwait = "10000" type = "codeph" text = "/codeph"/>
<Resource Name = "JDBC/Test2"
Auth = "container2"
Type = "javax. SQL. datasource"
Driverclassname = "oracle. JDBC. Driver. oracledriver"
Url = "JDBC: oracle: thin: @ 127.0.0.1: 1521: orcl"
Username = "Test2"
Password = "Test2"
Maxactive = "100"
Maxidle = "30"
Maxwait = "10000" type = "codeph" text = "/codeph"/>

2. Modify webapp/test/WEB-INF/Web. xml and add
<Resource-ref>
<Description> dB connection </description>
<Res-ref-Name> JDBC/test1 </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>
<Resource-ref>
<Description> dB connection </description>
<Res-ref-Name> JDBC/Test2 </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container2 </RES-auth>
</Resource-ref>

3. Program Call connection pool statement
/** The pooltag value is test1 or Test2 */
Public connection poolconnect (string pooltag ){
Connection conn = NULL;
Try {
Context Env = new initialcontext ();
Context envctx = (context) ENV. Lookup ("Java: COMP/ENV ");
Datasource pool = (datasource) envctx. Lookup ("JDBC/" + pooltag );
If (pool = NULL)
Throw new exception ("JDBC/" + pooltag + "is an unknown datasource ");
Conn = pool. getconnection ();
}
Catch (exception e ){
System. Err. println ("poolconnect:" + pooltag + "." + E. getmessage ());
}
Return conn;
}

------- Note in Nanchang. 2009.03.11

 

 

PS:

Tomcat6 memory insufficiency and Solution

1. Tomcat can use 128 MB of memory by default. In large application projects, this memory is insufficient and may cause the system to fail.

A common problem is the error of Tomcat memory overflow. the out of memory (insufficient system memory) causes the client to display the Error 500. Generally, the problem can be solved by adjusting the memory usage of Tomcat.

Modify the "% tomcat_home %/bin/Catalina. Bat" file in windows and add the following settings at the beginning of the file: Set java_opts =-xms256m-xmx512m

Modify the "% atat_home %/bin/Catalina. Sh" file in Linux and add the following settings at the beginning of the file: java_opts = '-xms256m-xmx512m'

Here,-XMS sets the initial memory size and-xmx sets the maximum memory that can be used.

 

2. The Catalina. BAT file is no longer available in Tomcat 6.

Run the % atat_home %/bin/tomcat6w.exe file and set the initial memory pool and maximum memory pool values to 256 and 512, respectively.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.