Posted on 2006-03-15 02:19
ikingqu 閱讀(191)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
Web/App Server
TOMCAT使用技巧
1 增加一個(gè)虛擬目錄
在server.xml文件中增加
<Context path="/oicq" docBase="myweb" debug="0" reloadable="true">
</Context>
myweb說(shuō)明其相對(duì)webapps的位置,是物理存在的目錄;
/oicq說(shuō)明其相對(duì)web URL的路徑,是一個(gè)虛擬的路徑,如:http://localhost/oicq
2 配置服務(wù)器的端口
在標(biāo)準(zhǔn)server.xml文件的第56行,修改port = “8080” 為你所希望使用的端口號(hào),如:80
3 web.xml文件的設(shè)置
默認(rèn)(歡迎)文件的設(shè)置
在h:\tomcat4\conf\web.xml中,<welcome-file-list>與IIS中的默認(rèn)文件意思相同。
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
報(bào)錯(cuò)文件的設(shè)置
<error-page>
<error-code>404</error-code>
<location>/notFileFound.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/null.jsp</location>
</error-page>
如果某文件資源沒(méi)有找到,服務(wù)器要報(bào)404錯(cuò)誤,按上述配置則會(huì)調(diào)用
H:\tomcat\webapps\ROOT\notFileFound.jsp。
如果執(zhí)行的某個(gè)JSP文件產(chǎn)生NullPointException ,則會(huì)調(diào)用H:\tomcat4\webapps\ROOT\null.jsp
典型的JSP錯(cuò)誤頁(yè)面應(yīng)該這樣寫(xiě):
<%@ page isErrorPage=”true”%>
出錯(cuò)了:<p> 錯(cuò)誤信息: <%= exception.getMessage() %></p>
Stack Trace is :
<pre>
<font color="red">
<%
java.io.CharArrayWriter cw = new java.io.CharArrayWriter();
java.io.PrintWriter pw = new java.io.PrintWriter(cw,true);
http://www.ChinaJavaWorld.com/ exception.printStackTrace(pw);
out.println(cw.toString());
%>
</font>
</pre>
會(huì)話超時(shí)的設(shè)置
設(shè)置session 的過(guò)期時(shí)間,單位是分鐘;
<session-config>
<session-timeout>30</session-timeout>
</session-config>
過(guò)濾器的設(shè)置
<filter>
<filter-name>FilterSource</filter-name>
<filter-class>project4. FilterSource </filter-class>
</filter>
<filter-mapping>
<filter-name>FilterSource</filter-name>
<url-pattern>/WwwServlet</url-pattern>
(<url-pattern>/haha/*</url-pattern>)
</filter-mapping>
過(guò)濾:
1) 身份驗(yàn)證的過(guò)濾Authentication Filters
2) 日志和審核的過(guò)濾Logging and Auditing Filters
3) 圖片轉(zhuǎn)化的過(guò)濾Image conversion Filters
4) 數(shù)據(jù)壓縮的過(guò)濾Data compression Filters
5) 加密過(guò)濾Encryption Filters
6) Tokenizing Filters
7) 資源訪問(wèn)事件觸發(fā)的過(guò)濾Filters that trigger resource access events XSL/T 過(guò)濾XSL/T filters
9) 內(nèi)容類(lèi)型的過(guò)濾Mime-type chain Filter 注意監(jiān)聽(tīng)器的順序,如:先安全過(guò)濾,然后資源,然后內(nèi)容類(lèi)型等,這個(gè)順序可以自己定。