tomcat应用技巧

来源:互联网 发布:php word转pdf 编辑:程序博客网 时间:2024/04/29 00:14
<script type="text/javascript"><!--google_ad_client = "pub-1401375761595447";/* 336x280, 创建于 08-2-25 */google_ad_slot = "7846511466";google_ad_width = 336;google_ad_height = 280;//--></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

  1 增加一个虚拟目录

  在server.xml文件中增加

  <Context path="/oicq" docBase="myweb" debug="0" reloadable="true"></Context>

  myweb说明其相对webapps的位置,是物理存在的目录;

  /oicq说明其相对web URL的路径,是一个虚拟的路径,如:http://localhost/oicq

  2 配置服务器的端口

  在标准server.xml文件的第56行,修改port = “8080” 为你所希望使用的端口号,如:80

  3 web.xml文件的设置

  默认(欢迎)文件的设置

  在h: omcat4confweb.xml中,<welcome-file-list>与IIS中的默认文件意思相同。

  <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

  报错文件的设置

  <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>

  如果某文件资源没有找到,服务器要报404错误,按上述配置则会调用H: omcatwebappsROOT otFileFound.jsp。

  如果执行的某个JSP文件产生NullPointException ,则会调用H: omcat4webappsROOT ull.jsp

  典型的JSP错误页面应该这样写:

  <%@ page isErrorPage=”true”%>
出错了:<p> 错误信息: <%= exception.getMessage() %></p>

  Stack Trace is :

  <font color="red">
<%
java.io.CharArrayWriter cw = new java.io.CharArrayWriter();
java.io.PrintWriter pw = new java.io.PrintWriter(cw,true);
exception.printStackTrace(pw);
out.println(cw.toString());
%>
</font>

  会话超时的设置

  设置session 的过期时间,单位是分钟;

  <session-config>
<session-timeout>30</session-timeout>
</session-config>

  过滤器的设置

  <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>

  过滤:

  1) 身份验证的过滤Authentication Filters

  2) 日志和审核的过滤Logging and Auditing Filters

  3) 图片转化的过滤Image conversion Filters

  4) 数据压缩的过滤Data compression Filters

  5) 加密过滤Encryption Filters

  6) Tokenizing Filters

  7) 资源访问事件触发的过滤Filters that trigger resource access events XSL/T 过滤XSL/T filters

  9) 内容类型的过滤Mime-type chain Filter 注意监听器的顺序,如:先安全过滤,然后资源,然后内容类型等,这个顺序可以自己定。

 
原创粉丝点击