• Jsp+servlet has been used to develop projects in recent projects, but difficulties have been caused by the lack of familiarity in the background. Fortunately, learning ability can also do one time to learn it.
• Today's question: After the request forwards the page garbled problem
• For special reasons-the form form that the picture uploads cannot be submitted via Ajax and must be submitted directly using form forms. But this can lead to a problem: the front background interaction is not effective. Why is the effect bad? This is not about the function of the problem. As a web developer, the customer experience we want to put in the first place. Therefore, we must put the customer feedback in a more important position. To put it bluntly, is to upload a picture did not succeed? Has the information I posted been uploaded successfully? If you upload something when the page does not respond, or jump directly to other pages, he will think it can, but actually did not upload to the server, there may be many reasons, such as my current network is not good, or the file is too large, or your files do not support, But this is difficult to understand as users who do not understand the code, they will think that your site is too rubbish.
• Therefore, we will try our most to think for the customer, the information they want to know to communicate to them.
• Of course, Ajax is practical, but in the case of file flow it is impossible to upload data via Ajax.
• Request.getrequestdispacher (' url '). Forward request forwarding and redirection came in handy. Redirection cannot share data, so only request forwarding can be used.
• Here, the files are Uploadservlet and user.jsp pages. When uploading a shopping message, all of my information has been plugged into the background and needs to be returned to the user to say that you succeeded. So the traditional way, Request.setattribute () is very practical, on the JSP page using request to get the value to determine whether the success of the.
* But after the forwarding back page garbled ...
• Search for information through many parties, and finally find solutions;
• Filters are configured to filter all files.
The
• Paste is as follows:
Package com.java.Filter;
Import java.io.IOException;
Import Javax.servlet.Filter;
Import Javax.servlet.FilterChain;
Import Javax.servlet.FilterConfig;
Import javax.servlet.ServletException;
Import Javax.servlet.ServletRequest;
Import Javax.servlet.ServletResponse;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse; public class Encodingfilter implements Filter {public void Destroy () {//TODO auto-generated method stub} publi c void Dofilter (ServletRequest req, Servletresponse resp, Filterchain chain) throws IOException, servletexception {H
Ttpservletrequest request = (httpservletrequest) req;
HttpServletResponse response = (httpservletresponse) resp;
Request.setcharacterencoding ("Utf-8");
Response.setcharacterencoding ("Utf-8");
Response.setcontenttype ("Text/html;charset=utf-8");
Chain.dofilter (request, response);
} public void init (Filterconfig arg0) throws Servletexception {//TODO auto-generated method stub
}
}
web.xml Configuration:
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class> com.java.filter.encodingfilter</filter-class>
</filter>
<filter-mapping>
< filter-name>encodingfilter</filter-name>
<url-pattern>/*</url-pattern>
</ Filter-mapping>
The above request to forward JSP page garbled problem fast solution is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.