The most complete process for processing garbled code in jsp does not require manual Transcoding

Source: Internet
Author: User

The most complete process for processing garbled code in jsp does not require manual Transcoding

Taking the encoding format as an example of UTF-8

1, jsp page file encoding format, right-click in eclipse-properties-resource-text file encode modify the UTF-8

2.

<%@ page  pageEncoding="UTF-8"%>
As above, the file storage format is used to store files and compile Chinese Characters

3.

<%@ page  contentType="text/html; charset=UTF-8" %>
Jsp page decoding format

4. jsp pageInside

 
The browser decoding format. If this format is not set, you can set it in the browser.
5. Add a filter to web. xml in the wen project.

 
 
  characterEncodingFilter
       
 
  org.springframework.web.filter.CharacterEncodingFilter
       
           
  
   encoding
            
  
   UTF-8
        
       
           
  
   forceEncoding
            
  
   true
        
   
     
  
   characterEncodingFilter
      
  
   /*
    
 
 
  
Do not miss it. Otherwise, garbled characters may appear when there are other filters.
 

This is actually equivalent to the jsp page

request.setCharacterEncoding("UTF-8")response.setCharacterEncoding ("UTF-8")

6. Set the Port location in the server. xml file in tomcat

    
 

7, if the use of <% @ include file = "../footer. jsp" %> requires both sides of the encoding completely consistent, such as not one side of UTF-8, one side of the UTF-8



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.