2006-1-26 19:44:11 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Java\jdk1.5.0_05\bin;.;C:\WINDOWS\system32;C:\WINDOWS;d:\ruby\bin;.;..;D:\Java\jrockit-R26.0.0-jdk
實(shí)際這是建議使用apache的apr。
如果想使用apr的話(huà), 實(shí)際操作很簡(jiǎn)單,
下載 http://tomcat.heanet.ie/native/1.1.1/binaries/win32/tcnative-1.dll
將這個(gè)文件復(fù)制到C:\WINDOWS\system32\下面
然后重新啟動(dòng)tomcat,就會(huì)發(fā)現(xiàn)tomcat 的控制臺(tái)信息為:
2006-1-26 19:48:42 org.apache.coyote.http11.Http11AprProtocol init
信息: Initializing Coyote HTTP/1.1 on http-9080
詳情見(jiàn) http://tomcat.apache.org/tomcat-5.5-doc/apr.html
![]() Core Servlets & JSP 2/E |
---|
![]() More Servlets & JSP |
Using Tomcat as a deployment server or integrating Tomcat as a plugin within the regular Apache server or a commercial Web server is more complicated than what is described in this tutorial. Although such integration is valuable for a deployment scenario (see http://jakarta.apache.org/tomcat/tomcat-5.5-doc/), my goal here is to show how to use Tomcat as a development server on your desktop. Regardless of what deployment server you use, you'll want a standalone server on your desktop to use for development.
The examples here assume you are using Windows, but they can be easily adapted for Linux, Solaris, and other versions of Unix. I've gotten many reports of successful use on MacOS X, but don't know the setup details. Except when I refer to specific Windows paths (e.g., C:\blah\blah), I use URL-style forward slashes for path separators (e.g., install_dir/webapps/ROOT). Adapt as necessary.
The information here is adapted from the introductory setup and configuration chapter of Core Servlets and JavaServer Pages, 2nd Edition, Volume 1 from Sun Microsystems Press and Prentice Hall. For the book table of contents, index, source code, etc., please see http://volume1.coreservlets.com/. For information on training courses (either at public venues or on-site at your company) taught by the author of the book and this Apache Tomcat tutorial, please see this servlet, JSP, Struts, JSF, and Java training courses page. To report errors or omissions in this writeup or to inquire about on-site training courses on servlets, JSP, Struts, JSF, and Java, please contact Marty Hall at hall@coreservlets.com.
Executive Summary |
---|
JSP, Servlet, Struts, & JSF Training | ||||||
---|---|---|---|---|---|---|
Looking for hands-on training? Tired of inexperienced instructors teaching someone else's course materials? Want a choice of public or in-house courses? Check out these servlet, JSP, Struts, and JSF training courses. Distinctive features:
|
PATH
is set so that both "java -version
" and "javac -help
" give a result.
JAVA_HOME
variable. Set it to refer to the base JDK directory, not the bin subdirectory.
port
attribute of the Connector
element from 8080 to 80.
<Context>
to <Context reloadable="true">
.
servlet
and servlet-mapping
elements that map the invoker
servlet to /servlet/*.
CATALINA_HOME
variable. Optionally, set CATALINA_HOME
to refer to the top-level Tomcat installation directory. Not necessary unless you copy the startup scripts instead of making shortcuts to them.
CLASSPATH
. Include the current directory ("."), the servlet/JSP JAR files (install_dir/common/lib/servlet-api.jar and install_dir/common/lib/jsp-api.jar), and your main development directory from Step 1.
CLASSPATH
includes the top level of your development directory. -d
option of javac
. Use -d
to tell Java where the deployment directory is.
ant
or a similar tool. Use the Apache make
-like tool to automate copying of files.
Install the JDK |
---|
Your first step is to download and install Java. The servlet 2.4 (JSP 2.0) specification requires JDK 1.3 or later; J2EE 1.4 (which includes servlets 2.4 and JSP 2.0) requires JDK 1.4 or later. You might as well get a recent Java version, so use JDK 1.4 or 1.5. If you know which of those Java versions will be used on your project, get that one. If not, I recommend JDK 1.4 instead of JDK 1.5 so that you don't limit portability by accidentally using Java 1.5 features in your code. See the following sites for download and installation information.
Once you've installed Java, confirm that everything including your PATH
is configured properly by opening a DOS window and typing "java -version
" and "javac -help
". You should see a real result both times, not an error message about an unknown command. Or, if you use an IDE, compile and run a simple program to confirm that the IDE knows where you installed Java.
Configure Tomcat |
---|
JSP, Servlet, Struts, & JSF Training | ||||||
---|---|---|---|---|---|---|
Looking for hands-on training? Tired of inexperienced instructors teaching someone else's course materials? Want a choice of public or in-house courses? Check out these servlet, JSP, Struts, and JSF training courses. Distinctive features:
|
JAVA_HOME
variable.
CATALINA_HOME
variable. (Optional; rarely used)
Details of each step are given below. If Tomcat is already running, restart it after performing these steps.
Go to http://jakarta.apache.org/site/binindex.cgi#tomcat and download the zip file for the current release build of Jakarta Tomcat 5.5. If you need to use an older version of Tomcat to be compatible with an app server such as BEA WebLogic 8.1 that does not support JSP 2.0, please see the older Apache Tomcat 5.0 and 4.0 tutorial.
Note that if you use Tomcat 5.5 with JDK 1.4 (the recommended setup for most users), you have to download both the main zip file and the "Compat" zip file. If you use Tomcat 5.5 with JDK 1.5, you do not need the "Compat" zip file, but it is better to use JDK 1.4 (unless you will deploy on JDK 1.5 only) so that you do not limit portability by accidentally using JDK 1.5 constructs in your Java code.
Save the zip file(s) on your PC and unzip into a location of your choice. You specify the top-level directory (e.g., C:\) and the zip file has embedded subdirectories (e.g., jakarta-tomcat-5.5.9). Thus, C:\jakarta-tomcat-5.5.9 is a common resultant installation directory. Note: from this point forward, I'll refer to that location as install_dir. For Windows, there is also a .exe installer; I prefer the .zip file, but see the .exe installer section for notes on the differences between the two.
Alternatively, you can use my preconfigured Jakarta Tomcat version. This version already has the port changed to 80, servlet reloading enabled, the invoker servlet turned on, and the "Compat" package included. It also comes with a sample development directory and autoexec.bat file.
JAVA_HOME
VariableNext, you must set the JAVA_HOME
environment variable to tell Tomcat where to find Java. Failing to properly set this variable prevents Tomcat from compiling JSP pages. This variable should list the base JDK installation directory, not the bin subdirectory. For example, on almost any version of Windows, if you installed the JDK in C:\j2sdk1.4.2_08, you might put the following line in your C:\autoexec.bat file.
set JAVA_HOME=C:\j2sdk1.4.2_08
On Windows XP, you could also go to the Start menu, select Control Panel, choose System, click on the Advanced tab, press the Environment Variables button at the bottom, and enter the JAVA_HOME
variable and value directly. On Windows 2000 and NT, you do Start, Settings, Control Panel, System, then Environment. However, you can use C:\autoexec.bat on those versions of Windows also (unless a system administrator has set your PC to ignore it).
Assuming you have no other server already running on port 80, you'll find it convenient to configure Tomcat to run on the default HTTP port (80) instead of the out-of-the-box port of 8080. Making this change lets you use URLs of the form http://localhost/blah instead of http://localhost:8080/blah. Note that you need admin privileges to make this change on Unix/Linux. Also note that some versions of Windows XP automatically start IIS on port 80. So, if you use XP and want to use port 80 for Tomcat, you may need to disable IIS (see the Administrative Tools section of the Control Panel).
To change the port, edit install_dir/conf/server.xml and change the port
attribute of the Connector
element from 8080 to 80, yielding a result similar to that below.
<Connector port="80" ... maxThreads="150" minSpareThreads="25" ...
You can also:
The next step is to tell Tomcat to check the modification dates of the class files of requested servlets, and reload ones that have changed since they were loaded into the server's memory. This slightly degrades performance in deployment situations, so is turned off by default. However, if you fail to turn it on for your development server, you'll have to restart the server every time you recompile a servlet that has already been loaded into the server's memory. Since this tutorial discusses the use of Tomcat for development, this change is strongly recommended.
To turn on servlet reloading, edit Edit install_dir/conf/context.xml and change
<Context>
to
<Context reloadable="true">
You can also:
The invoker servlet lets you run servlets without first making changes to your Web application's deployment descriptor (i.e., the WEB-INF/web.xml file). Instead, you just drop your servlet into WEB-INF/classes and use the URL http://host/servlet/ServletName (or http://host/webAppName/servlet/ServletName once you start using your own Web applications; see Section 2.11 of the book for details on Web apps). The invoker servlet is extremely convenient when you are learning and even when you are doing your initial development. You almost certainly want to enable it when learning, but you should disable it again before deploying any real applications.
To enable the invoker servlet, uncomment the following servlet
and servlet-mapping
elements in install_dir/conf/web.xml. Do not confuse this Apache Tomcat-specific web.xml file with the standard one that goes in the WEB-INF directory of each Web application.
<servlet> <servlet-name>invoker</servlet-name> <servlet-class> org.apache.catalina.servlets.InvokerServlet </servlet-class> ... </servlet> ... <servlet-mapping> <servlet-name>invoker</servlet-name> <url-pattern>/servlet/*</url-pattern> </servlet-mapping>
You can also:
If you use Windows 98/Me, you may also have to change the DOS memory settings for the startup and shutdown scripts. If you get an "Out of Environment Space" error message when you start the server, you will need to right-click on install_dir/bin/startup.bat, select Properties, select Memory, and change the Initial Environment entry from Auto to at least 2816. Repeat the process for install_dir/bin/shutdown.bat. This step is not necessary in more recent versions of Windows.
CATALINA_HOME
Variable (Optional)If you are going to make copies of the Tomcat startup or shutdown scripts (e.g., startup.bat and shutdown.bat), it is also helpful to set the CATALINA_HOME
environment variable to refer to the top-level directory of the Apache Tomcat installation (e.g., C:\jakarta-tomcat-5.5.9<%2
Tomcat作為一個(gè)很優(yōu)秀的web application server的確值得大家使用,特別是熟悉java的愛(ài)好者,不過(guò)它的配置并不象它的應(yīng)用那么優(yōu)秀,至少在配置上有很多瑣碎的事情要做,現(xiàn)在我將我自己配置最新的tomcat5.5.15的一點(diǎn)心得告訴大家:
總共涉及三個(gè)方面,也是tomcat配置比較煩瑣的地方
一.與apache的配置(暫略,晚點(diǎn)再將配置詳細(xì)介紹)
二.使tomcat5.5.15支持jstl標(biāo)簽
這個(gè)是最簡(jiǎn)單的配置,只要按照以下方法,就可以配置成功.
1.下載 jakarta-taglibs-standard-1.1.2.zip (windows)
jakarta-taglibs-standard-1.1.2.tar.gz(linux)
2.解壓在解壓的lib目錄下找到j(luò)stl.jar,standard.jar這兩個(gè).jar文件,將他們復(fù)制到 你的站點(diǎn)/WEB-INF/lib文件夾下,在tld目錄下將所有的.tld文件復(fù)制到 你的站點(diǎn)/WEB-INF/taglib/文件下
3.配置 你的站點(diǎn)/WEB-INF/web.xml文件,在</webapp>前添加如下內(nèi)容
<taglib>
<taglib-uri>http://www.hnlinux.net/core</taglib-uri>
<taglib-location>/WEB-INF/taglibs/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://www.hnlinux.net/fn</taglib-uri>
<taglib-location>/WEB-INF/taglibs/fn.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://www.hnlinux.net/sql</taglib-uri>
<taglib-location>/WEB-INF/taglibs/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://www.hnlinux.net/fmt</taglib-uri>
<taglib-location>/WEB-INF/taglibs/fmt.tld</taglib-location>
</taglib>
(注意我的<taglib-uri>引用了http://www.hnlinux.net,呵呵,所以大家如果按照這樣設(shè)置的話(huà),在jsp中引用jstl標(biāo)簽是記得采用這樣寫(xiě)<%@ taglib uri=http://www.hnlinux.net/core prefix="c" %>,可見(jiàn)這里配置是很靈活的隨便你取什么名字,只要在寫(xiě)jsp的時(shí)候相對(duì)應(yīng)就可以)
現(xiàn)在你就可以使用jstl來(lái)書(shū)寫(xiě)你的jsp了.
三.連接mysql數(shù)據(jù)庫(kù)的配置
1.下載 mysql-connector-java-5.0.0-beta.zip 將mysql-connector-java-5.0.0-beta-bin.jar復(fù)制到$Tomcat_home$/common/lib文件夾,(如果你不想使用數(shù)據(jù)連接池的話(huà),可以放在 你的站點(diǎn)/WEB-INF/lib文件夾下)
2.搞定了,你現(xiàn)在就可以使用連接數(shù)據(jù)庫(kù)的的相關(guān)語(yǔ)句了(這個(gè)是最簡(jiǎn)單的,呵呵)
四.mysql連接池的配置.
1.下載commons-dbcp-1.2.1.zip 解壓將commons-dbcp-1.2.1.jar復(fù)制到$Tomcat_home$/common/lib下(保證mysql的jdbc的驅(qū)動(dòng)也在此目錄)
2.修改$Tomcat_home$/cof/server.xml在context標(biāo)簽內(nèi)添加以下內(nèi)容,如果沒(méi)有找到context標(biāo)簽,注意在下面加上紅色的部分,蘭色部分根據(jù)自己情況修改,不用解釋了吧?
<Context path="/hasek" docBase="hasek"
debug="5" reloadable="true" crossContext="true">
<Resource name="hasek" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/hasek?autoReconnect=true"/>
</Context>
注意一點(diǎn)的事情是:<Context path="/hasek" docBase="hasek"... 中/hasek代表的是 你的站點(diǎn)
<Resource name="hasek" 這個(gè)hasek代表的是你的連接池的名字,這個(gè)要和下面的web.xml里的內(nèi)容相一致.
url="jdbc:mysql://localhost:3306/hasek?autoReconnect=true"/>中的hasek代表你的數(shù)據(jù)庫(kù)名字
3.修改 你的站點(diǎn)/WEB-INF/web.xml 在</webapp>標(biāo)簽前添加以下內(nèi)容:
<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>hasek</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4.測(cè)試代碼(連接池與jstl標(biāo)簽測(cè)試)test.jsp
<%@ taglib uri="http://www.hnlinux.net/sql" prefix="sql" %>
<%@ taglib uri="http://www.hnlinux.net/core" prefix="c" %>
<sql:query var="rs" dataSource="hasek">
select * from hasek
</sql:query>
<html>
<head>
<title>DB Test</title>
</head>
<body>
<h2>測(cè)試成功</h2>
<c:forEach var="row" items="${rs.rows}">
Foo ${row.id}<br/>
Bar ${row.num}<br/>
</c:forEach>
</body>
</html>
5.輸入http://localhost:8080/hasek/test.jsp看到測(cè)試成功字樣就說(shuō)明你配置ok了
安裝tomcat。并添加admin角色和用戶(hù)。
將jdbc驅(qū)動(dòng)包放到tomcat_home\common\lib目錄下。
在MyEclipse建立一個(gè)新的Web項(xiàng)目。使用剛才配置的tomcat作為服務(wù)器。
啟動(dòng)tomcat。
二、配置
打開(kāi)tomcat。
登錄 Tomcat Web Server Administration Tool.
點(diǎn)擊左側(cè)的Data Sources。
在右側(cè)Available Actions下拉菜單中選擇Create New Data Source.
輸入
JNDI Name:
Data Source URL:
JDBC Driver Class:
User Name:
Password:
Max.Active Connections:最大活動(dòng)連結(jié)數(shù) ,0為不限 。
Max.Idle Connections:最大等待連結(jié)數(shù) ,0為不限 。
Max.Wait for Connection:建立連接超時(shí)時(shí)間ms,-1為無(wú)限 。
注:使用SQLServer的官方JDBC驅(qū)動(dòng),Class=com.microsoft.jdbc.sqlserver.SQLServerDriver,URL=jdbc:Microsoft:sqlserver://127.0.0.1:1433;databaseName=aa;使用開(kāi)源的驅(qū)動(dòng)Jtds,Class=net.sourceforge.jtds.jdbc.sqlserver,URL=jdbc:jtds:sqlserver://127.0.0.1:1433/aa
輸入完畢,點(diǎn)擊“Save”按鈕保存。
點(diǎn)擊頁(yè)面右上側(cè)“Commit Changes”按鈕,保存剛才的設(shè)置。(這一步很重要哦!)
打開(kāi)tomcat_home\conf\server.xml的< GlobalNamingResources></ GlobalNamingResources>中找到
<Resource
name="jdbc/mydbcp"
type="javax.sql.DataSource"
password="aa"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
maxIdle="2"
maxWait="5000"
username="aa"
url="jdbc:microsoft:sqlserver://10.0.2.37:1433;databaseName=aa"
maxActive="4"/>
這是JNDI的主要配置文件,可以不使用圖形界面直接寫(xiě)入server.xml中。
在tomcat_home\webapps\dbcp\ META-INF\context.xml的<context></context>中填入上面的代碼。
如果更改了JNDI,則必須手動(dòng)更改context.xml。
<Resource
name="mydbcp" 注:此處不同
type="javax.sql.DataSource"
password="aa"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
maxIdle="2"
maxWait="5000"
username="aa"
url="jdbc:microsoft:sqlserver://10.0.2.37:1433;databaseName=aa"
maxActive="4"/>
和
<ResourceLink
global="jdbc/mydbcp"
name="jdbc/mydbcp"
type="javax.sql.DataSource"/>
重起tomcat。
連接方法:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/mydbcp");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from systypes");
三、測(cè)試
測(cè)試實(shí)例:test.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="java.sql.*,javax.sql.DataSource,javax.naming.*"%>
<html>
<head>
<title>
tomcat 連接池
</title>
</head>
<body bgcolor="#ffffff">
<h3>
test
<br>
連接池3
</h3>
<%try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/mydbcp");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from systypes");
while (rs.next()) {%>
<br>
<%=rs.getString(1)%>
<%}%>
<%out.print("<br>Successful!成功!!\n");%>
<%rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
out.print("出現(xiàn)例外!" + e.getMessage());
e.printStackTrace();
}
%>
</body>
</html>
四、錯(cuò)誤
錯(cuò)誤1:Cannot load JDBC driver class 'com.microsoft.jdbc.sqlserver.SQLServerDriver'
是沒(méi)有將sql jdbc driver包放在common\lib\目錄下。
錯(cuò)誤2:Cannot create PoolableConnectionFactory ([Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.)
SQL數(shù)據(jù)庫(kù)補(bǔ)丁包的問(wèn)題,如果訪問(wèn)的數(shù)據(jù)庫(kù)是SP3,任何問(wèn)題沒(méi)有。不是SP3就會(huì)出現(xiàn)上面的錯(cuò)誤。
錯(cuò)誤3:Name mydbcp is not bound in this Context
在context.xml中加入
<ResourceLink
global="jdbc/mydbcp"
name="jdbc/mydbcp"
type="javax.sql.DataSource"/>
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<Resource
name="mysql/xscj"
type="javax.sql.DataSource"
password="kingsoft88"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://202.118.133.88:3306/xscj"
maxActive="4"/>
</Context>
<html>
<head>
<title></title>
<%
out.print("開(kāi)始測(cè)試:"+"<br/>");
DataSource ds = null;
Connection con=null;
try{
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup("java:comp/env");
//這里的數(shù)據(jù)庫(kù)前文提及的Data Source URL配置里包含的數(shù)據(jù)庫(kù)。
ds = (DataSource)ctx.lookup("jdbc/xscj");
con=ds.getConnection();
Statement stmt = con.createStatement();
String strSql = "select * from xs"; //表中的字段讀者自行添加
ResultSet rs = stmt.executeQuery(strSql);
while(rs.next()){
out.print(rs.getString(1)+"<br/>");
}
rs.close();
stmt.close();
con.close();
out.print("我的測(cè)試結(jié)束");
}
catch(Exception ex){
out.print("出現(xiàn)例外,信息是:”+ ex.getMessage());
ex.printStackTrace();
}
%>
</head>
<body>
</body>
</html>
今天下載了5.5.12版的TOMCAT,折騰了半天才知道TOMCAT5.0.28之后就沒(méi)有了默認(rèn)的admin模塊,還以為我的配置哪出錯(cuò)了(花了半小時(shí)沒(méi)找出原因:()。下面是網(wǎng)上當(dāng)?shù)囊恍╆P(guān)于TOMCAT配置方面的技巧,對(duì)相關(guān)的配置方法在沒(méi)有改動(dòng)原文的同時(shí)也做了適當(dāng)修改,已紅色字標(biāo)記。目前使用的是最新的jdk為1.5+tomcat5.5.12這里只給出簡(jiǎn)單的配置。
JDK1.5:
JAVA_HOME=c:\j2sdk1.5
classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;(.;一定不能少,因?yàn)樗懋?dāng)前路徑)
path=%JAVA_HOME%\bin
Tomcat 5.5.12:
CATALINA_HOME:c:\tomcat
CATALINA_BASE:c:\tomcat
TOMCAT_HOME: C:\Tomcat
修改classpath,classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\common\lib\servlet.jar; 啟動(dòng)tomcat,在IE中訪問(wèn)http://localhost:8080,如果看到tomcat的歡迎頁(yè)面的話(huà)說(shuō)明安裝成功了。
下面可能會(huì)是經(jīng)常出現(xiàn)和遇到的問(wèn)題:
1.下載http://www.eu.apache.org/dist/jakarta/tomcat-5/
這里注意,在jakarta-tomcat-5.0.28.exe以前是有默認(rèn)的admin模塊,在jakarta-tomcat-5.5.9.exe則沒(méi)有安裝默認(rèn)的admin模塊,這時(shí)http://127.0.0.1:8080/admin打開(kāi)時(shí)則會(huì)出現(xiàn)
Tomcat's administration web application is no longer installed by default. Download and install the "admin" package to use it.
因此我們現(xiàn)在需要下載"admin"package 包
把jakarta-tomcat-5.5.x.zip 與 jakarta-tomcat-5.5.x-compat.zip 與 jakarta-tomcat-5.5.x-admin.zip三個(gè)文件解壓在同一個(gè)目錄中(如果使用jdk1.4,才需要compat.zip用jdk1.5就可以免了這個(gè)。) 如果使用的是JDK1.5+tomcat5.5.12只需要將jakarta-tomcat-5.5.x-admin.zip文件解壓到TOMCAT目錄即可.
2.修改jakarta-tomcat-5.5.x\conf\tomcat-users.xml.
添加管理員賬號(hào)lizongbo,密碼為lizongbopass.(一般在安裝Tomcat的同時(shí)已提示輸入用戶(hù)名及密碼,如果有設(shè)置此處可不做修改。)
新xml如下:
有時(shí)在%CATALINA_HOME%\server\webapps\admin\WEB-INF\web.xml里面也要做些修改
The role that is required to log in to the Administration Application
admin
無(wú)論是 Authetication (身份驗(yàn)證還是 Authorization ( 權(quán)限管控都只有設(shè)置相關(guān)的admin ROLE,當(dāng)你想要新增或修改相關(guān)的AA, 就必須修改這一個(gè)文件,來(lái)符合你的環(huán)境.
3.修改jakarta-tomcat-5.5.x\conf\server.xml來(lái)解決編碼問(wèn)題。
(給Connector 添加URIEncoding參數(shù),參考http://blog.csdn.net/darkxie/archive/2004/10/25/TOMCATAPP.aspx)
(可以設(shè)置成GB18030)
enableLookups="false" redirectPort="8443" acceptCount="200"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"
compression="on" compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"/>
(這個(gè)還是比較頭痛的問(wèn)題,試了幾種方法都不是太理想,有待繼續(xù)解決,maxHttpHeaderSize="8192")
4.啟用支持gzip壓縮.
(http://www.linuxaid.com.cn/forum/showdoc.jsp?l=1&i=81169)
添加下列屬性
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"
5.設(shè)置虛擬主機(jī)。
在jakarta-tomcat-5.5.x\下建立文件夾vhost\www.mydomain.com。
然后修改jakarta-tomcat-5.5.x\conf\server.xml
6.添加數(shù)據(jù)庫(kù)驅(qū)動(dòng),更新mail.jar和actiovation.jar
復(fù)制mysql-connector-java-3.0.16-ga-bin.jar,pg74.215.jdbc3.jar到 jakarta-tomcat-5.5.x\common\lib\
還有javamail 1.3.2的mail.jar,jaf-1_0_2的 activation.jar
msSQl 2000 JDBC sp3,msbase.jar,msutil,jar,mssqlserver.jar
7.配置SSL
參考 http://jakarta.apache.org/tomcat/tomcat-5.5-doc/ssl-howto.html
D:\j2sdk1.4.2_06\bin>%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA
輸入keystore密碼: lizongbossl
您的名字與姓氏是什么?
[tomcat5.5.x]: tomcat5.5.x
您的組織單位名稱(chēng)是什么?
[jakarta]: jakarta
您的組織名稱(chēng)是什么?
[apache]: apache
您所在的城市或區(qū)域名稱(chēng)是什么?
[hzcity]: hzcity
您所在的州或省份名稱(chēng)是什么?
[gdp]: gdp
該單位的兩字母國(guó)家代碼是什么
[CN]: CN
CN=tomcat5.5.x, OU=jakarta, O=apache, L=hzcity, ST=gdp, C=CN 正確嗎?
[否]: y
輸入
(如果和 keystore 密碼相同,按回車(chē)):
(必須密碼一致,因此直接回車(chē))
然后再把userhome(例如:C:\Documents and Settings\lizongbo\)下的.keystore復(fù)制到
tomcat的conf\目錄下。
(例如:D:\jakarta-tomcat-5.5.x\conf\.keystore
配置jakarta-tomcat-5.5.x\conf\server.xml
加上
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="conf/.keystore"
keystorePass="lizongbossl">
8.禁止文件目錄列表,
修改jakarta-tomcat-5.5.x\conf\web.xml,把listing設(shè)置為false
9.指定了自己的javaEncoding
(參考 http://gceclub.sun.com.cn/staticcontent/html/sunone/app7/app7-dg-webapp/ch6/ch6-4.html
10.添加rar,iso等的mime-type映射
避免在瀏覽器里直接打開(kāi)。
10.1對(duì)html靜態(tài)頁(yè)面設(shè)置編碼
11.添加welcome-file-list,并調(diào)整順序。