jsp页面向后台传值出现乱码的问题

来源:互联网 发布:神州航天软件怎么样 编辑:程序博客网 时间:2024/06/04 21:16
今天做普通的前台页面向后台传值,要传值的内容是中文,传到后台打印一看 居然内容变成了 “?????”
于是在网上找了一些方法  :

1、采用decode()方法

 页面:

[html] view plain copy
  1. Url: '<%=path%>/sfyh/infodata.jsp?type='+encodeURI(ss)  

,


  后台:

[html] view plain copy
  1. String result = java.net.URLDecoder.decode(type,"UTF-8")  

2、采用设置字符集的方式
[html] view plain copy
  1. request.setCharacterEncoding("utf-8")  


3、在页面上定义charset的字符集(最有效 最简单

[html] view plain copy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"    
  2.         pageEncoding="utf-8"%>    
  3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  

 

4、采用转码的方式

页面:

[html] view plain copy
  1. Url: '<%=path%>/sfyh/infodata.jsp?type='+encodeURIComponent(ss)  



后台:
[html] view plain copy
  1. resultnew String(request.getParameter("type").getBytes("ISO8859-1"),"UTF-8")  
原创粉丝点击