a、设置页面编码,若是jsp页面,需编写代码<%@page language=“java” pageEncoding=“UTF-8” contentType=“text/html;charset=UTF-8” %>
若 是 html 页 面 , 在 网 页 头 部 ( < head>< /head> ) 中 添 加 下 面 这 段 代 码 < meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />
b 、 将 form 表 单 提 交 方 式 变 为 post 方 式 , 即 添 加 method=“post”; ) 在 Servlet 类 中 编 写 代 码request.setCharacterEncoding(“UTF-8”),而且必须写在第一行。
c 、 如 果 是 get 请 求 , 在 Servlet 类 中 编 写 代 码 byte [] bytes = str.getBytes(“iso-8859-1”);String cstr = new String(bytes,“utf-8”);
或者直接修改Tomcat服务器配置文件server.xml增加内容:URIEncoding=“utf-8”
如何解决表单提交的中文乱码问题
解决页面乱码的编码设置方法
最新推荐文章于 2022-03-17 17:04:58 发布
博客介绍了解决页面乱码的方法。对于jsp页面,需设置特定编码代码;html页面则在头部添加编码代码。form表单提交采用post方式,并在Servlet类中设置编码。对于get请求,可在Servlet类中转换编码,或修改Tomcat服务器配置文件。
246

被折叠的 条评论
为什么被折叠?



