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