Java EE's web (Servlet 3.0) Configuration Tutorial

Source: Internet
Author: User
Tags xsl tld

Xml:
Is the most basic configuration file of the Java EE Project, the portal of the server loading project,
Of course, 3.0. You can also configure a series of parameters that your project requires in your code.
Web. XML exists in Tomcat conf, and the configuration in the project inherits and overrides the file's configuration.


Basic configuration:
1. Welcome File Settings:

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

This is the default configuration of Web. XML in Tomcat, which is defined in the project.

2. Error Handling settings:

<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 a 404 error, and the above configuration would call \webapps\root\notfilefound.jsp.
If a JSP file is executed that produces nullpointexception, it is called \webapps\root\null.jsp

3. Answer Timeout setting:

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

Set the session expiration time, in minutes,
The Tomcat default value is 30min.

There are a number of security settings starting with servlet3.0:

 <session-config>       Session connection, maintain state settings:    <cookie-config>     <secure> true</secure>      only allows interaction under SSL, the default value is False.    


4. Filter settings:

<filter> <filter-name>openEntityManagerInViewFilter</filter-name> <filter-class> Org.springframework.orm.jpa.support.openentitymanagerinviewfilter</filter-class> <async-supported> true</async-supported> </filter> <filter-mapping> <filter-name>openentitymanagerinviewfil Ter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>


1) Authentication filtering authentication Filters
2) Log and audit filtering logging and Auditing Filters
3) Image conversion filter Image conversion Filters
4) Filter data compression Filters
5) encryption Filter Encryption Filters
6) tokenizing Filters
7) Resource access event triggered filtering filters that trigger resource access events xsl/t filter xsl/t filters
8) Content Type Filter Mime-type chain filter Note the order of the listeners, such as: first security filtering, then resources,
Then the content type, and so on, this order can be self-determined.

Tomcat built-in Filter:ssifilter, Setcharacterencodingfilter, Failedrequestfilter.
The default is on.

5.Servlet Management:

<servlet> <servlet-name>default</servlet-name> <servlet-class> Org.apache.catalina.servlets.defaultservlet</servlet-class> <init-param> <param-name>debug< /param-name> <param-value>0</param-value> </init-param> <init-param> <param-name >listings</param-name> <param-value>false</param-value> </init-param> <load-on-star Tup>1</load-on-startup></servlet>


Tomcat built-in servlet
With default on: Defaultservlet,jspservlet,
Default off: Ssiservlet,cgiservlet


6. Apply the image to indicate:

<icon> <small-icon>/images/small.gif</small-icon> <large-icon>/images/large.gif</ Large-icon></icon>

Small:16 x 16,large:32 x 32. Suffix extension:. gif or. jpg.

7. Apply Global Context Parameters

<context-param> <param-name>param_name</param-name> <param-value>param_value</ Param-value></context-param>

8. Listener Listener:

<listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class ></listener>

The listener is responsible for monitoring the various event states of the server and application.

The listener for content in Tomcat has
Aprlifecyclelistener,jasperlistener,jrememoryleakpreventionlistener,
Globalresourceslifecyclelistener,threadlocalleakpreventionlistener
These listeners are configured by default in Server.xml.


9. Media mapping <mime-mapping>

<mime-mapping> <extension>doc</extension> <mime-type>application/msword</mime-type ></mime-mapping>

When a static resource is requested, Tomcat automatically adds a Content-type header based on the suffix name to map the media type.
The Tomcat built-in contains many mapping configurations, which are appended in Web. XML if required.
Note: If the custom code download file must be added in response to the Content-type header.


10.jsp Configuration <jsp-config>
The Jsp-config element is primarily used to set the relevant configuration of the JSP,<jsp:config> including <taglib> and <jsp-property-group> two sub-elements.

<jsp-config>    <taglib>         The Taglib element contains two child elements Taglib-uri and taglib-location. Used to set the tag library path used by the JSP Web page .         <taglib-uri>URI</taglib-uri>         The taglib instruction of the URI,JSP Web page that defines the TLD file can be accessed to the TLD file via this URI .        < Taglib-uri taglib-location>/web-inf/lib/xxx.tld</taglib-laction>         The TLD file corresponds to the location of the Web platform .    </taglib>    <jsp-property-group>         <description>Description</descrition>          description of this setting         <display-name> name</display-name>         name of this setting          <url-pattern> url</url-pattern>         the range affected by the setpoint, such as:/ch2  or/*.jsp         <el-ignored>true|false</el-ignored>          true to indicate that El syntax is not supported .        < scripting-invalid>true|false</scripting-invalid>         True indicates that the <%scription%> syntax is not supported.         <page-encoding>encoding </page-encoding>         set the encoding of JSP pages          <include-prelude>.jspf</include-prelude>          set the header of the JSP Web page with the extension. jspf        <include-coda>.jspf</ include-coda>         set the end of the JSP Web page with the extension .jspf     </jsp-property-group><jsp-coNfig> 

11. Resource Management Object Configuration

<resource-env-ref> <resource-env-ref-name>jms/StockQueue</resource-env-ref-name> </ Resource-env-ref>


12. Resource Factory Configuration

<resource-ref> <res-ref-name>mail/Session</res-ref-name> <res-type>javax.mail.session </res-type> <res-auth>Container</res-auth> </resource-ref>


The configuration database connection pool can be configured here:

<resource-ref> <description>jndi JDBC DataSource of shop</description> <res-ref-name>jdbc/ Sample_db</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>container& Lt;/res-auth> </resource-ref>


13, Security restrictions configuration

<security-constraint>     <display-name>Example Security  constraint</display-name>     <web-resource-collection>      <web-resource-name>Protected Area</web-resource-name>      <url-pattern>/jsp/security/protected/*</url-pattern>     < Http-method>delete 


14. Login Verification Configuration

<login-config> <auth-method>FORM</auth-method> <realm-name>example-based Authentiation is A</realm-name> <form-login-config> <form-login-page>/jsp/security/protected/login.jsp</ Form-login-page> <form-error-page>/jsp/security/protected/error.jsp</form-error-page> </ Form-login-config> </login-config>

15. Security role: The Security-role element gives a list of security roles that will appear in the Role-name child elements of the security-role-ref element within the servlet element.
Declaring roles separately makes it easier for advanced Ides to handle security information.

<security-role> <role-name>tomcat</role-name> </security-role>



16. Web Environment parameter: Env-entry element declares environment item for web App

<env-entry> <env-entry-name>minExemptions</env-entry-name> <env-entry-value>1</ Env-entry-value> <env-entry-type>java.lang.Integer</env-entry-type> </env-entry>


refer to :
Http://www.cnblogs.com/JesseV/archive/2009/11/17/1605015.html

How does tomcat load and parse Web. xml?

The load order is:

Context-param->listener->filter->servlet

please refer to :
Http://www.csdn123.com/html/blogs/20130919/71581.htm
http://blog.csdn.net/insistgogo/article/details/22598001


Java EE's web (Servlet 3.0) Configuration Tutorial

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.