• In recent projects, jsp+servlet was used to develop projects, but due to lack of proficiency in the background, it has caused many difficulties. Fortunately, you can learn your learning ability while doing it all.
•Today's question: garbled page after requesting forwarding
• Due to special reasons - the form form uploaded by the image cannot be submitted through ajax, so it must be submitted directly using the form form. But this will lead to a problem: the effect is not good when interacting with the front and back stages. Why is the effect not good? What we are talking about here is not a problem of function. As web developers, we should put customer experience first. Therefore, we must place feedback on customers’ information in a relatively important position. To put it bluntly, is it just that uploading an image successfully? Have the information I posted been uploaded successfully? If the web page does not respond when you upload something, or jumps directly to other pages, he will think it is OK, but in fact it is not uploaded to the server. There may be many reasons, such as my current network is not good, the file is too large, or your file does not support it, but this is difficult for users who do not understand code. They will think that your website is too garbage.
• Therefore, we will try our best to think for our customers and convey the information they want to know to them.
•Of course, ajax is very practical, but it is impossible to upload data through ajax in the case of file streams.
•So ('url').forward request forwarding and redirecting come in handy. Redirection cannot share data, so it can only use request forwarding.
• Here, the file is uploadServlet and the page. When uploading shopping information, all my information has been inserted into the background and I need to return the information for the user and say, you have succeeded. Then the traditional method, () is very practical. Just use request to get the value on the jsp page to determine whether it is successful.
•But after forwarding, the page is garbled. . .
• After searching for information from multiple parties, the solution was finally found;
•Filters are configured to filter all files.
•The following is now pasted:
package ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class EncodingFilter implements Filter { public void destroy() { // TODO Auto-generated method stub } public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; ("utf-8"); ("utf-8"); ("text/html;charset=UTF-8"); (request, response); } public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub } }
•Configuration:
<filter> <filter-name>EncodingFilter</filter-name> <filter-class></filter-class> </filter> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
The quick solution to the above request to forward the garbled jsp page problem is the full content I share with you. I hope you can give you a reference and I hope you support me more.