JSP page Transfer value garbled filtering method _jsp programming

Source: Internet
Author: User

This article describes the JSP page transfer value garbled filtering method. Share to everyone for your reference, specific 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 > <filter-name>CharacterEncodingFilter</filter-name> <!--this name with <filter-mapping> under < Filter-name> the same--> <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-lis  t> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> 

When I submit with the default submission of <form>, this method can not filter, need to set method= "POST" to filter

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

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.