request.getRequestDispatcher("login.html");转换页面时出现汉字乱码
直接进入login.html页面没问题,用上述方法RequestDispatcherdispatcher=request.getRequestDispatcher("lo...
直接进入login.html页面没问题,用上述方法
RequestDispatcher dispatcher=
request.getRequestDispatcher("login.html");
dispatcher.include(request,response);
就有问题
html页面的设置是UTF-8
servlet页面的设置是
response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8");
求解惑,谢谢 展开
RequestDispatcher dispatcher=
request.getRequestDispatcher("login.html");
dispatcher.include(request,response);
就有问题
html页面的设置是UTF-8
servlet页面的设置是
response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8");
求解惑,谢谢 展开
3个回答
展开全部
login.html文件本身的编码也应该是UTF-8,另外也可以加个字符编码过滤器自动进行转换。
public class Encoding implements Filter {
private String encode = "UTF-8";
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
request.setCharacterEncoding(encode);
chain.doFilter(req, resp);
}
public void init(FilterConfig config) throws ServletException {
String str = config.getInitParameter("encode");
if (str != null && str.length() > 0)
encode = str;
}
}
public class Encoding implements Filter {
private String encode = "UTF-8";
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
request.setCharacterEncoding(encode);
chain.doFilter(req, resp);
}
public void init(FilterConfig config) throws ServletException {
String str = config.getInitParameter("encode");
if (str != null && str.length() > 0)
encode = str;
}
}
展开全部
request.setCharacterEncoding("GBK");
放在RequestDispatcher dispatcher=
request.getRequestDispatcher("login.html");
dispatcher.include(request,response);
前面
把里面的PrintStream out=。。。;注释掉
放在RequestDispatcher dispatcher=
request.getRequestDispatcher("login.html");
dispatcher.include(request,response);
前面
把里面的PrintStream out=。。。;注释掉
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在login.html 的<head>里增加
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Title</title>
</head>
servlet 的post和get 用utf-8编码显示,html中用gb2312显示
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Title</title>
</head>
servlet 的post和get 用utf-8编码显示,html中用gb2312显示
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询