热门文章 | 热门软件| 热门源码 | 热门电影 | 知识库 | 联系我们
软件 源码 教程 影视 健康 招聘
  HTML | JavaScript | ASP | PHP | JSP | NET | VB | VC | VF | Windows | Linux | Mysql | Mssql | Oracle | Struts 
当前位置: 创世纪计算机资源网 -> 文章频道 ->struts 
站内搜索:
从STRUTS传参数到JAVA文档中出现乱码解决办法
作者:阿栋 来源:blog 整理日期:2007-8-13

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

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

<%@ page contentType="text/html;charset=GBK"%>

再在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!

相关文章