A quick solution to the issue of request forwarding jsp page Garbled text, forward jsp page Garbled text

Source: Internet
Author: User

A quick solution to the issue of request forwarding jsp page Garbled text, forward jsp page Garbled text

• Jsp + servlet was used in the latest project to develop the project, but it was difficult due to poor background proficiency. Fortunately, you can continue to learn it.

• Today's problem: Garbled text on the page after request forwarding

• For special reasons, form forms uploaded to images cannot be submitted through ajax, so they must be submitted directly using form forms. However, this will lead to a problem: the front-and-back-end interaction is ineffective. Why is the effect poor? This is not a function issue. As web developers, we need to put customer experience first. Therefore, we must put customer feedback in a more important position. To put it bluntly, is uploading an image unsuccessful? Have I successfully uploaded the published information? If the webpage does not respond when you upload things, or you directly jump to another page, he will think it is okay, but it is not actually uploaded to the server, there may be many reasons, for example, my current network is poor, the file is too large, or your file is not supported, but this is hard to understand as a user who does not understand the code, they will think that your website is too spam.

• Therefore, we will try our best to think for our customers and send the information they want to know to them.

• Ajax is very practical, but it cannot upload data through ajax in the case of file streams.

• Request. getRequestDispacher ('url'). forward requests are used for forwarding and redirection. However, redirection cannot share data, so only request Forwarding is allowed.

• The file is the uploadServlet and user. jsp pages. When uploading the shopping information, all the information has been inserted into the background. You need to return the information to the user, saying that you have succeeded. In the traditional method, request. setAttribute () is very practical. You can use the request value on the jsp page to determine whether the request is successful.

• The page is garbled after it is forwarded back...

• The solution was finally found through searching materials from multiple parties;

• Configure the filter to filter all files.

• Paste 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 } public void doFilter(ServletRequest req, ServletResponse resp,  FilterChain chain) throws IOException, ServletException {  HttpServletRequest 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 quick solution to the above issue of forwarding jsp page garbled characters is all the content shared by Alibaba Cloud xiaobian. I hope you can provide a reference and support for the customer's house.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.