Tomcat Usage Tips

Source: Internet
Author: User

1 Add a virtual directory

Add in Server.xml file

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

MyWeb shows that its relative WebApps position is the catalogue of physical existence;

/oicq describes the path to its relative web URL, which is a virtual path, such as: Http://localhost/oicq

2 Configuring the server's ports

In line 56th of the standard server.xml file, modify port = "8080" For the port number you wish to use, such as: 80

3 Web.xml File Settings

Settings for default (welcome) files

The,<welcome-file-list> in H:omcat4confweb.xml is the same as the default file in 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>

Settings for an error file

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

If a file resource is not found, the server will report 404 errors, and the above configuration will call H:omcatwebappsroot otfilefound.jsp.

If a JSP file is executed that produces nullpointexception, the H:omcat4webappsroot ull.jsp is invoked

A typical JSP error page should be written like this:

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

Settings for session timeout

Set the expiration time of the session, in minutes;

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

Settings for filters

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

Filter:

1) Authentication Filter Authentication Filters

2 log and audit filtering logging and auditing Filters

3 Image Transformation Filter image conversion Filters

4 data compression filtering compression Filters

5) encryption Filter Encryption Filters

6) tokenizing Filters

7) Resource access event-triggered filtering filters that trigger resource access events XSL/T filtering xsl/t filters

9 Content Type Filter Mime-type chain filter attention to the order of listeners, such as: first safe filtering, then resources, and then content type, this order can be set itself.

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.