1, the Web configuration:
(1), set error Jump interface:
(2), String encoding configuration:
<!--character Set encoding configuration-->
<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), configure Serlvet interception request out of 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>
The class of the configuration collection (Implementing filter):
Implementing multiple Servet Configurations in Web.xml
public class Redispatcherfilter implements Filter {public void Destroy () {} public void Dofilter (ServletRequest Req, Servletresponse resp, Filterchain chain) throws IOException, servletexception {httpservletrequ
EST Request = (httpservletrequest) req;
String target = Request.getrequesturi (); target = Target.lastindexof ("?") > 0? Target.substring (Target.lastindexof ("/") + 1, target.lastindexof ("?")-Target.lastindexo
F ("/"): 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 to register (upload file to server):
<!--register 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>