jsp页面,增加操作提交之后显示乱码,直接显示没有问题,请问你是怎样解决的呀?
答案:3 悬赏:60 手机版
解决时间 2021-02-19 19:01
- 提问者网友:凉末
- 2021-02-18 18:39
jsp页面,增加操作提交之后显示乱码,直接显示没有问题,请问你是怎样解决的呀?
最佳答案
- 五星知识达人网友:迟山
- 2021-02-18 18:54
写个过滤器,下面这个过滤器写的太简单!!,但便于理解
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.HttpServlet;
public class CharacterEncodingFilter extends HttpServlet implements Filter {
@Override
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// request.setCharacterEncoding("UTF-8");
// response.setCharacterEncoding(request.getCharacterEncoding());
chain.doFilter(request, response);
}
public void init(FilterConfig arg0) throws ServletException {
}
}
在你的web.xml中加入如下代码
characterEncoding
com.filter.CharacterEncodingFilter
characterEncoding
/*
---------------------------------------------------------------------------------------------------
com.filter.CharacterEncodingFilter这是过滤器类路径.com.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.HttpServlet;
public class CharacterEncodingFilter extends HttpServlet implements Filter {
@Override
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// request.setCharacterEncoding("UTF-8");
// response.setCharacterEncoding(request.getCharacterEncoding());
chain.doFilter(request, response);
}
public void init(FilterConfig arg0) throws ServletException {
}
}
在你的web.xml中加入如下代码
---------------------------------------------------------------------------------------------------
com.filter.CharacterEncodingFilter这是过滤器类路径.com.filter是包名!
全部回答
- 1楼网友:往事隔山水
- 2021-02-18 19:56
写一个专门拦截jsp页面的字符集过滤器应该就可以解决了。
- 2楼网友:渊鱼
- 2021-02-18 19:42
啊,我将全部页面的编码变为utf-8,不是的话,用过滤器将他们全部变为utf-8,还有就是注意数据库的排序方式,(我用的是sql server )
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯