从STRUTS页面中传中文参数,在JAVA文件中用request.getPrameter("value")接收参数之后是乱码,
这样的问题首先要保证在JSP页面和JAVA页面中使用的编码都是统一的编码,而且在JSP页面中文件头加上以下语句:
jsp 代码
- <%@ page contentType="text/html;charset=GBK"%>
再在JAVA中使用以下字符串内码转换方法:
java 代码
- //把以iso编码转换为字符串内码
- String tempName = request.getParameter("value");
- String name = null;
- try {
- name = new String(tempName.getBytes("ISO-8859-1"),"GBK");
- } catch (UnsupportedEncodingException e1) {
- // TODO 自动生成 catch 块
- e1.printStackTrace();
- }
这样就OK!