Beginners are useful: Web. XML Common Elements

Source: Internet
Author: User

The most basic configuration in Java Web Development this piece: Web. XML, a lot of beginners do not understand, it's okay, let's see what are the commonly used configurations? first, let's take a look at the most streamlined Struts2+spring+hibernate collection framework of Web. XML
<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "3.0" xmlns= "Http://java.sun.com/xml/ns/javaee"       Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "> <display-name>sshdemo-<span style=" line-height: 21.6000003814697px; Font-family:consolas, ' bitstream Vera Sans Mono ', ' Courier New ', Courier, monospace; " > </span><span style= "LINE-HEIGHT:1.8EM; Font-family:consolas, ' bitstream Vera Sans Mono ', ' Courier New ', Courier, monospace; " ></display-name> </span> <!--add support for spring, that is, configure the listener--<context-param> <param -name>contextconfiglocation</param-name> <param-value>classpath:applicationcontext.xml</ param-value> </context-param> <listener> <listener-class>org.springframework.web . Context. Contextloaderlistener</listener-class> </listener> <!--add support for Struts2, which is to configure the Struts2 interceptor, which intercepts requests-and <filte R> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter . Strutsprepareandexecutefilter</filter-class> </filter> <!--when hibernate+spring is used, if lazy= is set True, when reading the data, Hibernate automatically closes the session when the parent data is read, so that when the child data is used, the system throws a lazyinit error, which requires the use of the spring-provided Opensessioni      Nviewfilter,opensessioninviewfilter is mainly to keep the session state know that request will send all pages to the client, so that you can solve the problem of lazy loading-<filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class> Org.springframework.orm.hibernate4.support.opensessioninviewfilter</filter-class> <init-param> &lt ;p aram-name>singlesession</param-name> <param-value>true</param-value> </init-param&gt    ; </filter> <!--struts2 intercept match symbol,/* indicates match all, whenThen you can write *.action or *.do--> <filter-mapping> <filter-name>struts2</filter-name> <url-patte rn>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>opensessioninvi ewfilter</filter-name> <url-pattern>*.do,*.action</url-pattern> </filter-mapping> &lt ;! --Here is the simplest, welcome page, which is to access this Web item popup with a page--<welcome-file-list> <welcome-file>index.jsp</welcome-file&    Gt   </welcome-file-list> </web-app>

---------------------------------------------------The following is a description of common tags:---------------------------------------------------
<web-app> <display-name></display-name> defines the name of the Web App <description></description>    Declares that the Web app's description <context-param></context-param> Context-param element declares an application-scoped initialization parameter. <filter></filter> The filter element relates a name to a class that implements the Javax.servlet.Filter interface (for example, struts2 interceptors: Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteF    Ilter).    <filter-mapping></filter-mapping> Once a filter is named, it should be associated with one or more servlet or JSP pages using the filter-mapping element.                         Version 2.3 of the <listener></listener>servlet API adds support for event listeners, which are notified when a session or servlet environment is established, modified, and deleted. The listener element indicates the event listener class. (commonly used such as Spring Listener: Org.springframework.web.context.ContextLoaderListener) <servlet></servlet> When you set initialization parameters or custom URLs to a servlet or JSP page, you must first name the servlet or JSP page.    The servlet element is used to accomplish this task. The <servlet-mapping></servlet-mapping> server typically provides a default url:http://host/webappprefix/servlet/for Servlets                Servletname. <span style= "color: #008000;" > However, this URL is often changed so that the servlet can access the initialInitialize parameters or more easily handle relative URLs.     </span> Use the servlet-mapping element when changing the default URL.              <session-config></session-config> If a session is not accessed for a certain amount of time, the server can discard it to save memory.     You can explicitly set a time-out value for a single Session object by using the Setmaxinactiveinterval method of HttpSession, or you can use the Session-config element to make a default timeout.    <mime-mapping></mime-mapping> The Mime-mapping element provides this assurance if the Web app has a special file that you want to guarantee to assign to them a specific MIME type.    <welcome-file-list></welcome-file-list> indicates which file the server uses when it receives a URL that references a directory name instead of a file name.    <error-page></error-page> can make a page that will be displayed when a specific HTTP status code is returned, or when a particular type of exception is thrown. <taglib></taglib> specifies aliases for tag library descriptor files (tag Libraryu descriptor file).    This feature enables you to change the location of TLD files without editing the JSP pages that use those files.    <resource-env-ref></resource-env-ref> declares a management object that is associated with a resource.    <resource-ref></resource-ref> declares an external resource used by a resource factory. <security-constraint></security-constraint> develop URLs that should be protected. It is used in conjunction with the Login-config element <login-config></login-config> specifies how the server should authorize users attempting to access a protected page.    It is used in conjunction with the Sercurity-constraint element. <security-role></security-role> 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.    <env-entry></env-entry> declares the environment item for the web App.    <ejb-ref></ejb-ref> declares a reference to the home directory of an EJB.    < ejb-local-ref></Ejb-local-ref> declares the application of an EJB's local home directory.     </web-app>
---------------------------------------------------want to see more web. XML introduction? ---------------------------------------------------
This is for beginners to see, is basically enough. Of course, Web. XML also has a lot of configuration to see more detailed configuration.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Beginners are useful: Web. XML Common Elements

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.