SSM配置文件

来源:互联网 发布:ps手绘效果图软件 编辑:程序博客网 时间:2024/06/09 17:37
一、总的:web.xml
<!--配置上下文:applicationContext.xml -->
  <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath*:/applicationContext.xml</param-value>
  </context-param>


<!--配置encodeFilter -->


<filter>
  <filter-name>encodingFilter</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>encodingFilter</filter-name>
  <url-pattern>/*</url-pattern>  //对所有的文件进行过滤
  </filter-mapping>


在过滤器文件(比如这里是ActionFilter文件)中加入下面的代码:




if(requestURIName.endsWith(".jsp")||requestURIName.endsWith(".js")||requestURIName.endsWith(".css")){


        chain.doFilter(httpRequest, httpResponse);


        return;


}


比如这里是把以jsp,js和css为后缀的文件放过去,不对他们进行过滤。
如果想对其他类型的文件进行过滤的话,只要把相应文件的后缀名加到上面的代码就可以了。




<!--监听器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>




<!-- 配置servlet-->
<servlet>
  <servlet-name>springServlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring-mvc.xml</param-value>
  </init-param>

  <load-on-startup>1</load-on-startup>

//Load-on-startup 元素在web应用启动的时候指定了servlet被加载的顺序,它的值必须是一个整数。如果它的值是一个负整数或是这个元素不存在,那么容器会在该servlet被调用的时候,加载这个servlet 。如果值是正整数或零,容器在配置的时候就加载并初始化这个servlet,容器必须保证值小的先被加载。如果值相等,容器可以自动选择先加载谁。  

  </servlet>
  <servlet-mapping>
  <servlet-name>springServlet</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>


<!--错误页面配置-->
  <error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/WEB-INF/views/error/500.jsp</location>
</error-page>
  <error-page>
  <error-code>400</error-code>
  <location>/WEB-INF/views/error/400.jsp</location>
  </error-page>
  <error-page>
  <error-code>500</error-code>
  <location>/WEB-INF/views/error/500.jsp</location>
  </error-page>


0 0
原创粉丝点击