1、web的配置:
(1)、设置错误跳转界面:
(2)、字符串编码配置:
<!-- 字符集编码配置 -->
<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>
(3)、配置serlvet 拦截请求脱离struct2之外
<filter>
<filter-name>redisp</filter-name>
<filter-class>yamadv.com.filter.ReDispatcherFilter</filter-class>
<init-param>
<param-name>includeServlets</param-name>
<param-value>FileImageUploadServlet,uploadProcessorServlet</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>redisp</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
/// 该配置集合的类(实现filter):
实现多个servet在web.xml中的配置
public class ReDispatcherFilter implements Filter {
public void destroy() {}
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
String target = request.getRequestURI();
target = target.lastIndexOf("?") > 0 ? target.substring(
target.lastIndexOf("/") + 1,
target.lastIndexOf("?") - target.lastIndexOf("/")) : target
.substring(target.lastIndexOf("/") + 1);
System.out.println(target);
if (this.includes.contains(target)) {
RequestDispatcher rdsp = request.getRequestDispatcher(target);
System.out.println("go..............." + rdsp);
rdsp.forward(req, resp);
} else{
chain.doFilter(req, resp);
}
}
private ArrayList<String> includes = new ArrayList<String>();
public void init(FilterConfig config) throws ServletException {
this.includes.addAll(Arrays.asList(config.getInitParameter(
"includeServlets").split(",")));
}
}
//要注册的servet(上传文件到服务器):
<!-- 注册 FileImageUploadServlet 的servlet -->
<servlet>
<servlet-name>FileImageUploadServlet</servlet-name>
<servlet-class>yamadv.com.upload.FileImageUploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FileImageUploadServlet</servlet-name>
<url-pattern>/FileImageUploadServlet</url-pattern>
</servlet-mapping>