in the Itoo in , each War under the Bag Web. XML It's all the same. . It is structured as follows :
The Itoo contains multiple war packages, and the Web. XML in each war package is the same structure, and the configuration content is the same.
in theJavawebThe app can containHTMLDocument, servlet,jspand relatedJavaclass, etc.,toServletcontainers can be successfully foundJavawebindividual components in the app, ServletRegulatory Requirements, Javawebapplications must take a fixed directory structure,that is, each type of componentWebThere are fixed storage directories in the application. ServletThe specification also stipulates that, JavawebThe application configuration information is stored in theWeb-inf/web.xmlin the file, Servletcontainer reads configuration information from this file.
WEB the composition of the application:
QRC Project Name
|
|----index.html,jsp .... "files under the root directory can be accessed directly by the outside world"
|
|----Web-inf directory "files in this directory cannot be accessed directly by the outside world, there are Web the server is responsible for invoking the
| |---classes directory (java Class)
| |---lib directory ( the jar required for Java classes to run )
| |--- the Web. Xml file ( The configuration file for the application)
each one Javaweb all projects have a Web. XML configuration file, what does he really do? Is it a must for every Web project?
Web. XMLfiles are used to initialize the project configuration information, for exampleWelcomepage,Filter,Listener,servlet,servlet-mapping, start the load level, and so on,Web. XMLfile isJavawebof the applicationXMLconfiguration files in the format,stored inWeb-infSub-Directory. Web. XMLfiles written by developers,forServletContainer Access. Web. XMLfiles are also known asJavawebApp Release profile, Servletcontainers are loaded and startedJavawebthe application will read itsWeb. XMLfile,get information about the currentWebpublished information for the app.when you haveWebIt doesn't have to be in the works, and of course it doesn't need this.XMLfile to configure yourapllicationthe
Each xml file has a web.xml xml Schema How many label elements are defined in the file, web.xml web.xml sun company defined, each web.xml The root element of the file is <WEB-APP> web.xml which schema file is used.
so , Web. XML file is Web an indispensable configuration file in your app. He is an XML file by itself. Adhere to the syntax of the XML file. In the Web. xml file
can contain the following configuration information :
. Servlet definition .
. servlet the initialization parameters
. servlet and JSP the mapping
. security Domain Configuration Parameters
. Welcome List of documents .
. Resource References
definition of environment variables .
Servlet2.5 version of Web. XML adopted a XmlSchema to define XML elements;
Web. XML description of the element:
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:18PX;" ><web-app> <description> <description> Description of the current Web application, this is a descriptive information, optional </description> < Display-name> <display-name> The name of the Web App management page displayed in the Web app, optional </display-name> <distributable> < Distributable/> <!--load Balancing, applications are distributed--<filter> <filter> <filter-name>authenticationfilter </filter-name> <filter-class>webbook.guestbook.AuthenticationFilter</filter-class> < Init-param> <param-name>url</param-name> <param-value>/admin/login.jsp</param-value> </init-param> </filter> <filter-mapping> <filter-mapping> <filter-name> Authenticationfilter</filter-name> <url-pattern>/admin/secure/*</url-pattern> <url-pattern >/admin/manage/*</url-pattren> </filter-mapping> <context-param> <context-param> < Param-name>pagesize</param-name> <param-value>30</param-value> </context-param> <listener> <listener> <listener-class> webbook.user.onlineuserlistener</listener-class> </listener> <servlet> <servlet> < Servlet-name>addmessageservlet</servlet-name> <servlet-class>webbook.guestbook.addmessageservlet <servlet-class> <init-param> <param-name>type</param-name> <param-value>text</ param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> < Servlet-mapping> <servlet-mapping> <servlet-name>AddMessageServlet</servlet-name> < Url-pattern>/servlet/addmessage</url-pattern> </servlet-mapping> <session-config> < session-config> <session-timeout>60</session-timeout> </session-config> <mime-mapping> <mime-mapping> <extension>xls</extension> <mime-type>application/vnd.ms-excel</ Mime-type> </mime-mapping> <welcome-file-list> <welcome-file-list> <welcome-file>index.jsp</welcome-file> < Welcome-file>index.htm</welcome-file> <welcome-file>addMessage.jsp</welcome-file> </ welcome-file-list> <error-page> <error-page> <error-code>404</error-code> <location >/error404.htm</location> </error-page> <error-page> <exception-type> Java.io.ioexception</exception-type> <location>/error500.jsp</location> </error-page> </span>
--------------------------------------------------------------------------
Web Application Initialization
1 , first of all, put in Web. XML in the file <listener> The listener that is declared by the element is instantiated;
2 , and then, call those that implement the Servletcontextlistener interface of the listener. contextinitialized () method;
3 , instantiation <filter> The filter class declared in the element, which invokes the Init () method;
4 , and finally, if <servlet> element is used in the <load-on-startup> child elements, the values are small to large, in turn
servlet is instantiated, and calls the corresponding servlet of the Init () method;
said so much. , use the following two graphs to explain the following Web. XML in the Javaweb the role of :
Web Server and Web apply these two different software systems to collaborate , need an intermediary Servlet container to handle .
Web. XML in the configuration implementation servlet implementation of the interface .
Web Server is loading Web when applied , it will put the corresponding Web. XML the data in the file is read into memory , So when Web Server needs reference Web. XML file when , Actually, you just need to read the relevant data from memory and torture. , no more reading to the file system Web. XML file .
so , the Web The file can be read in advance to the memory .
"Java" Itoo project the role of the web in the Java Web