从STRUTS页面中传中文参数,在JAVA文件中用request.getPrameter("value")接收参数之后是乱码,

这样的问题首先要保证在JSP页面和JAVA页面中使用的编码都是统一的编码,而且在JSP页面中文件头加上以下语句:

jsp 代码
 
  1. <%@ page contentType="text/html;charset=GBK"%>  

再在JAVA中使用以下字符串内码转换方法:
java 代码
 
  1. //把以iso编码转换为字符串内码  
  2.  String tempName = request.getParameter("value");  
  3.  String name = null;  
  4.  try {  
  5.     name = new String(tempName.getBytes("ISO-8859-1"),"GBK");  
  6.    } catch (UnsupportedEncodingException e1) {  
  7.        // TODO 自动生成 catch 块  
  8.        e1.printStackTrace();  
  9.    }  

这样就OK!


评论
发表评论

您还没有登录,请登录后发表评论

BIGN
搜索本博客
我的相册
D11df183-2b86-3c41-811f-336e641f7879-thumb
denglu
共 25 张
存档
最新评论