JSP page garbled filtering method, jsp page garbled Filtering

Source: Internet
Author: User

JSP page garbled filtering method, jsp page garbled Filtering

This article describes how to filter out the garbled characters of JSP page values. We will share this with you for your reference. The details are as follows:

1. filter class:

package com.token.t1;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;public class CharacterEncodingFilter implements Filter {  public void destroy() {  }  public void doFilter(ServletRequest request, ServletResponse response,      FilterChain chain) throws IOException, ServletException {     request.setCharacterEncoding("gbk");    chain.doFilter(request, response);  }  public void init(FilterConfig arg0) throws ServletException {  }}

2. xml file Configuration:

<? Xml version = "1.0" encoding = "UTF-8"?> <Web-app version = "2.5" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <! -- Filter configuration --> <filter-name> CharacterEncodingFilter </filter-name> <! -- This name is the same as <filter-mapping> <filter-name> <filter-class> com. token. t1.CharacterEncodingFilter </filter-class> </filter> <filter-mapping> <filter-name> CharacterEncodingFilter </filter-name> <url-pattern>/* </url-pattern> </filter-mapping> <display-name> </display-name> <welcome-file-list> <welcome-file> index. jsp </welcome-file> </welcome-file-list> </web-app>

When I use the default submission method of <form>, this method cannot be filtered. You need to set method = "post" to filter.

I hope this article will help you with JSP program design.

Articles you may be interested in:
  • Application of ajax json value passing Method on jsp page
  • Example of ajax value passing in checkbox Using jsp
  • Example of how to solve Chinese garbled characters in jsp value passing
  • Jquery ajax submits a form from the action to the jsp implementation Summary
  • Solve the Problem of garbled characters on the local test machine without garbled characters when passing jsp values
  • Two kinds of data transfer between Servlet and JSP
  • Analysis on the issue of passing values between JSP pages

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.