关于Form表单提交中文乱码问题
来源:互联网 发布:js调用另一个js的函数 编辑:程序博客网 时间:2024/05/23 02:00
form表单使用get方法输入中文:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<form action="http://localhost:8080/SecondProj/servlet/HelloForm" method="GET" >
名字:<input type="text" name="first_name" >
<br />
姓氏:<input type="text" name="last_name" />
<input type="submit" value="提交" />
</form>
</body>
</html>
然后使用servlet的doGet方法获取输入值:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 设置响应内容类型
response.setContentType("text/html");
// response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String title = "使用 GET 方法读取表单数据";
String docType = "<!doctype html public \"-//w3c//dtd html 4.0 "
+ "transitional//en\">\n";
out.println(docType + "<html>\n" + "<head><title>" + title
+ "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n"
+ "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n"
+ " <li><b>名字</b>:" + request.getParameter("first_name")
+ "\n" + " <li><b>姓氏</b>:" + request.getParameter("last_name")
+ "\n" + "</ul>\n" + "</body></html>");
}
点击提交显示的页面输入的内容是乱码,只有输入的内容是乱码!
百度了好多,有的说是jsp的page-encoding要设置成utf-8,有的说是request.setContentType(“text/html;charset=utf-8”),还有的说是修改Tomcat的conf文件夹里的server.xml文件里面的<Connector>标签的URIEncoding=“UTF-8”,结果都不管用。
后来看到说是修改Tomcat的conf文件夹里的server.xml文件里面的<Connector>标签的URIEncoding=“GBK”,我当时想的是,utf-8就支持汉字,也不管用,换成gbk就行了?根本没去试,隔了一天实在没辙了就去试了,bingo!成了哎,unbelievable!
但是我还是不清楚为什么utf-8格式不行...
我知道了,右键查看页面信息可以看到页面的文字编码是gbk,所以要转成gbk格式的!
2017-3-24更新:其实,String str = request.getParameter(“name值”);之后,String newStr = new String(str.getBytes("ISO-8859-1"),"GBK")就行了。
- 关于提交form表单中文乱码问题
- 关于Form表单提交中文乱码问题
- form表单提交中文乱码问题
- form表单提交中文乱码问题
- form表单提交中文乱码
- form表单提交乱码问题
- struts中form表单提交过程中的中文乱码问题
- struts中form表单提交给Servlet中文乱码问题
- jsp中form表单提交到serlvet中文乱码问题
- Spring MVC 解决form表单提交中文乱码问题
- form表单提交中文乱码问题,dwz ModelAndView跳转form中有中文参数乱码
- 表单form内容提交,中文乱码解决
- easyui form表单提交中文乱码
- 【Java】form表单提交中文乱码
- form表单post提交时中文乱码
- 关于form表单提交乱码的解决办法
- 【解决方案】nodejs关于post提交表单的中文乱码问题
- form提交表单 后台乱码问题
- JBPM工作流引擎之并发流程&组任务&事件&自定义任务
- NODEMCU刷入AT固件后
- 双向链表
- 自定义拦截器
- 服务器配置git
- 关于Form表单提交中文乱码问题
- 第十章:Java_IO流
- enginx之于分布式部署的创新意义:服务器的服务器,通用分布式服务器引擎,集群引擎-使任何服务器程序纳入统一生态
- Can’t connect to local MySQL server through socket 解决办法
- (45). Spring Boot MyBatis连接Mysql数据库【从零开始学Spring Boot】
- SparkMlib实现线性回归
- 小知识积累(2)
- 外部存储属性extern
- Android OkHttp 框架学习