网络编程 
首页 > 网络编程 > 浏览文章

请求转发jsp页面乱码问题的快速解决方法

(编辑:jimmy 日期: 2024/11/8 浏览:3 次 )

"color: #ff0000">"background-color: #ccffcc">"htmlcode">

package com.java.Filter;

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;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class EncodingFilter implements Filter
{

 public void destroy()
 {
 // TODO Auto-generated method stub

 }

 public void doFilter(ServletRequest req, ServletResponse resp,
  FilterChain chain) throws IOException, ServletException
 {
  HttpServletRequest request = (HttpServletRequest) req;
  HttpServletResponse response = (HttpServletResponse) resp;
  request.setCharacterEncoding("utf-8");
  response.setCharacterEncoding("utf-8");
  response.setContentType("text/html;charset=UTF-8");
  chain.doFilter(request, response);
 }

 public void init(FilterConfig arg0) throws ServletException
 {
 // TODO Auto-generated method stub

 }
}

"htmlcode">

<filter>
  <filter-name>EncodingFilter</filter-name>
  <filter-class>com.java.Filter.EncodingFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>EncodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

以上这篇请求转发jsp页面乱码问题的快速解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

上一篇:jsp获得本地及serverIP的简单方法
下一篇:JSP+MySQL实现网站的登录与注册小案例