<web-app> <!--指定WEB应用的名字--> <display-name>MyWeb</display-name> <!--WEB应用描述信息--> <description>MyWeb demo</description> <!--web的初始化参数,通过ServletContextEvent.getServletContext().getInitParameter("field")获得value的值(ServletContextEvent通过listener获得)--> <context-param> <param-name>contextConfigLocation</para-name> <param-value>classpath:applicationContext.xml</param-value> <description>web的ApplicationContext上下问文件配置</description> </context-param> <!--filter 和filter-mapping 必须是成对出现--> <!--拦截/*的路径,执行CharacterEncodingFilter的父类的OncePerRequestFilter的doFilter(doFilter中调用doFilterInternal方法,设置request和response的编码方式设置为UTF-8)--> <filter> <filter-name>utf8-encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>utf8-encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--servlet 监听配置,项目启动时执行contextInitialized(ServletContextEvent servletContextEvent)方法,项目停止时执行contextDestroyed(ServletContextEvent event)--> <listener> <listerner-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--servlet和servlet-mapping是成对出现的,服务启动时,执行HttpServlet.init(ServletConfig config)方法,当用户请求/myservlet/*路径时,执行HttpServlet.service(HttpServletRequest req, HttpServletResponse resp)方法--> <servlet> <servlet-name>myservlet</servlet-name> <servlet-class>javax.servlet.http.HttpServlet</servlet-class> <init-param> <param-name>paramField</param-name> <param-value>paramValue</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>myservlet</servlet-name> <url-pattern>/myservlet/*</url-pattern> </servlet-mapping> <!--会话超时时间设置,单位是分钟--> <session-config> <session-timeout>10</session-timeout> </session-config> <!--mime-mapping元素将mime类型映射到扩展名, 用于规定下载格式--> <mime-mapping> <extension>htm</extension> <mime-type>text/html</mime-type> </mime-mapping> <mime-mapping> <extension>pdf</extension> <mime-type>application/pdf</mime-type> </mime-mapping> <mime-mapping> <extension>doc</extension> <mime-type>application/msword</mime-type> </mime-mapping> <mime-mapping> <extension>xls</extension> <mime-type>application/msexcel</mime-type> </mime-mapping> <!--指定Web项目的欢迎页面--> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list> <!--当请求发生404错误时,跳转到404error.jsp页面--> <error-page> <error-code>404</error-code> <location>/404error.jsp</location> </error-page> <!--当Web服务发生java.lang.NullException异常时,跳转到nullerror.jsp页面--> <error-page> <exception-type>java.lang.NullException</exception-type> <location>/nullerror.jsp</location> </error-page> <!--对tag库文件名称。前端JSP可以通过<%@ taglib uri="http://jakarta.apache.org/tomcat/debug-taglib" prefix="myTag"%>配置使用tag库--> <taglib> <taglib-uri>http://jakarta.apache.org/tomcat/debug-taglib</taglib-uri> <taglib-location>/WEB-INF/tld/taglib.tld</taglib-location> </taglib> <!--配置资源相关的管理对象,可通过new InitialContext().lookup()获得值--> <resource-env-ref> <resource-env-ref-name>jms/StockQueue</resource-env-ref-name> </resource-env-ref> <!--设置factory的外部资源--> <resource-ref> <description>java JDBC DataSource factory</description> <res-ref-name>jdbc/java_db</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>dataManager</res-auth> </resource-ref> <security-constraint></security-constraint> <login-config></login-config> <security-role></security-role> <env-entry></env-entry> </web-app>