转载  关于ssh三大框架中web.xml的总结

分类: 2015-04-05T15:32:40    315人阅读   

大家都知道,在常用的ssh框架开发中,web.xml是全局配置文件,那么在该xml文件中都需要配置什么?

1.配置actionservlet的初始化路径

<servlet>
           <servlet-name>action</servlet-name>
           <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
           <init-param>
                 <param-name>config</param-name>
                 <param-value>
                            
/WEB-INF/struts-config.xml,
                           /WEB-INF/struts-config.xml(可以配置多个文件,中间用,隔开)
                </param-value>
          </init-param>
          <init-param>
                   <param-name>debug</param-name>
                   <param-value>3</param-value>
          </init-param>
          <init-param>
                  <param-name>detail</param-name>
                  <param-value>3</param-value>
          </init-param>
          <load-on-startup>0</load-on-startup>
    </servlet>

相应的action的映射文件:
 <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
 </servlet-mapping>

相应的 <servlet-name>action</servlet-name>必须一致。
2.配置过滤器的初始化路径:
   <filter>
     <filter-name>encoding</filter-name>
     <filter-class>过滤文件的处理类</filter-class>
     <init-param>
      <param-name>encoding</param-name>
         <param-value>UTF-8</param-value>
      </init-param>
   </filter>
   <filter-mapping>
     <filter-name>encoding</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>
3.配置欢迎界面:
    <welcome-file-list>
        <welcome-file>welcome.jsp</welcome-file>
        <welcome-file>welcome.jsp</welcome-file>
   </welcome-file-list>
4.配置404错误界面:
 <error-page>
    <error-code>404</error-code>
    <location>/404.jsp</location>
 </error-page>
5.配置500错误界面:
   <error-page>
           <error-code>500</error-code>
           <location>/500.jsp</location>
  </error-page>


6.配置ServletException错误界面:
    <error-page>
            <exception-type>javax.servlet.ServletException</exception-type>
            <location>/systemError.jsp</location>
     </error-page>
7.设置session超时:
    <session-config>
        <!-- 以分钟为单位 -->
        <session-timeout>15</session-timeout>
    </session-config>
8.禁用scriptlet:
    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <scripting-invalid>true</scripting-invalid>
        </jsp-property-group>
    </jsp-config>
9.Spring配置文件

 <context-param>
                 <param-name>contextConfigLocation</param-name>
                 <param-value> WEB-INF/classes/configs/applicationContext.xml</param-value>
          </context-param>

 <servlet>
               <servlet-name>SpringContextServlet</servlet-name>
               <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
              <load-on-startup>2</load-on-startup>
          </servlet>

10.登陆过滤

<filter>
                <filter-name>loginFilter</filter-name>
               <filter-class>com.filter.LoginFilter</filter-class>
              <init-param>
                    <param-name>sessionName</param-name>
                   <param-value>user</param-value>
              </init-param>
             <init-param>
                    <param-name>loginURL</param-name>
                    <param-value>/cdp/pages/login/login.jsp</param-value>
            </init-param>
      </filter>
      <filter-mapping>
               <filter-name>loginFilter</filter-name>
               <url-pattern>*.do</url
-pattern>
      </filter-mapping>
      <filter-mapping>
              <filter-name>loginFilter</filter-name>
             <url-pattern>*.jsp</url-pattern>
     </filter-mapping>

 

11.数据库连接池

<servlet>
                 <servlet-name>ServletConfigurator</servlet-name>
                 <servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
                <init-param>
                     <param-name>xmlFile</param-name>
                    <param-value>WEB-INF/classes/configs/proxool.xml</param-value>
               </init-param>
               <load-on-startup>1</load-on-startup>
         </servlet>

 

12.hibernate配置

<filter>
                     <filter-name>hibernateFilter</filter-name>
                     <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
                    <init-param>
                             <param-name>singleSession</param-name>
                            <param-value>true</param-value>
                    </init-param>
                   <init-param>
                             <param-name>flushMode</param-name>
                             <param-value>AUTO</param-value>
                   </init-param>
      </filter>
     <filter-mapping>
                  <filter-name>hibernateFilter</filter-name>
                  <url-pattern>*.mmg</url-pattern>
     </filter-mapping>
     <filter-mapping>
                 <filter-name>hibernateFilter</filter-name>
                <url-pattern>/*</url-pattern>
     </filter-mapping>

 

暂时就配置这么些,如果还有什么其他配置,欢迎各位留言。将及时添加!!!

需要协助加Q群IT部落 OR 391053981

分享到: