Jsp uses a filter to solve Chinese Garbled text. jsp Chinese
Define a filter to implement the Filtter Interface
public class EncodingFilter implements Filter {@Overridepublic void destroy() {// TODO Auto-generated method stub}@Overridepublic void doFilter(ServletRequest req, ServletResponse resp,FilterChain chain) throws IOException, ServletException {// TODO Auto-generated method stubHttpServletRequest request=(HttpServletRequest)req;HttpServletResponse response=(HttpServletResponse)resp;request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");chain.doFilter(req, resp);}@Overridepublic void init(FilterConfig filterConfig) throws ServletException {// TODO Auto-generated method stub}}
Configure the filter in the web. xml file
<filter> <filter-name>EncodingFilter</filter-name> <filter-class>pers.filter.EncodingFilter</filter-class> </filter><filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
The above jsp uses a filter to solve Chinese Garbled text. It is all the content shared by Alibaba Cloud xiaobian. I hope you can give us a reference and support for the customer's house.