jsp中国文字形式提交,request对象获取乱码
2015-10-12 15:23
337 查看
jsp表单提交中文字符,request对象获取时乱码解决方法
第一种:
在request对象获取页面Charset中的“C”大写,且页面无中文字符,最好用英文,否则MyEclipse无法保存此页面编码(表单页面能够不大写“C”)
<%@ page contentType="text/html;Charset=GB2312" %>
另外一种:
tomcat4.x支持中文传码。但5.x不支持。假设用5.0以上的版本号就得转码了。
就是这样的格式
<%@ page contentType="text/html;charset=GB2312" %>
String strKeyWords=new String(request.getParameter("key_words").getBytes("iso8859_1"),"gb2312");
这个是我们的项目解决sqlserver中文乱码的方案。能够试试看
--------------------------------------------------------------------------
第三种:
在 jsp、servlet中 申明这种方法转换一下: (表单JSP页面的编码一定要GB2312,且
charset中的“c”小写。此方法JSP页面就能够写中文字符
即:<%@
page contentType="text/html;charset=GB2312" %>)
第四种:
在request对象获取提交的页面开头写(注意:此方法表单提交方式仅仅能是post,并且表单页码的编码方式和request.setCharacterEncoding("utf-8");
必须保持一致)
<%@
page contentType="text/html; charset=utf-8"%>
<% request.setCharacterEncoding("utf-8"); %>
第一行是页面编码方式
第二行是传值编码方式
表单页面
request对象获取页面
第一种:
在request对象获取页面Charset中的“C”大写,且页面无中文字符,最好用英文,否则MyEclipse无法保存此页面编码(表单页面能够不大写“C”)
<%@ page contentType="text/html;Charset=GB2312" %>
另外一种:
tomcat4.x支持中文传码。但5.x不支持。假设用5.0以上的版本号就得转码了。
就是这样的格式
<%@ page contentType="text/html;charset=GB2312" %>
String strKeyWords=new String(request.getParameter("key_words").getBytes("iso8859_1"),"gb2312");
这个是我们的项目解决sqlserver中文乱码的方案。能够试试看
--------------------------------------------------------------------------
第三种:
在 jsp、servlet中 申明这种方法转换一下: (表单JSP页面的编码一定要GB2312,且
charset中的“c”小写。此方法JSP页面就能够写中文字符
即:<%@
page contentType="text/html;charset=GB2312" %>)
<%!public String handleString(String str){ try{ byte bb[]=str.getBytes("ISO-8859-1"); str=new String(bb); }catch(Exception e){ System.out.println("字符转换失败"+e); } return str; } %> <% String logname=request.getParameter("參数ID"); logname=handleString(logname); %>
第四种:
在request对象获取提交的页面开头写(注意:此方法表单提交方式仅仅能是post,并且表单页码的编码方式和request.setCharacterEncoding("utf-8");
必须保持一致)
<%@
page contentType="text/html; charset=utf-8"%>
<% request.setCharacterEncoding("utf-8"); %>
第一行是页面编码方式
第二行是传值编码方式
表单页面
<%@ page contentType="text/html; charset=utf-8"%> <html> <body> <form method="post" action="2.jsp"> <div align="center"> <input type="text" name="name"> <input type="submit" name="Submit" value="Submit"> </div> </form> </body> </html> </span>
request对象获取页面
<%@ page contentType="text/html; charset=utf-8"%> <% request.setCharacterEncoding("utf-8"); %> <html> <body> <%=request.getParameter("name")%> </body> </html></span>
相关文章推荐
- iOS仿京东分类菜单之UICollectionView内容
- UVA-1612 Guess (贪心)
- Pop Sequence
- 关于UITableView多余分割线的优化
- 哈希+前缀和 hdu5496 Beauty of Sequence
- (ArcGIS API For Silverlight )QueryTask 跨层查询,和监控完整的查询!
- AdapterView类mBlockLayoutRequests、mInLayout变量简介
- silverlight中使用NavigationContext.QueryString动态加载文章
- 安卓中用迭代直接显示json中的key+value
- 如何创建圆角 UITextField 与内阴影
- kendoui笔记
- hdu 1159 Common Subsequence(最长公共子序列 DP)
- 手把手教你接口自动化测试 – SoapUI & Groovy
- hdu 1711 Number Sequence
- hdu 2817 A sequence of numbers(快速幂取余)
- hdu 1509 Windows Message Queue (优先队列)
- 【UI布局优化】Android布局优化的几种方式
- UICollectionView
- 解决PKIX:unable to find valid certification path to requested target 的问题
- HashMap按照value值进行排序