jsp页面的数据传到后台的时候老是乱码,我的jsp页面如下:<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<% 
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html ; charset=GBK"/> 
<title>信息整合平台</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="StyleSheet" href="CSS/sinorcaish-print.css" type="text/css"
media="print" />
<script src="scripts/jquery-1.6.js" type="text/javascript">
</script>
</head> <body>
<script type="text/javascript">
$(function() {
$('#submit').click(function() {
var num = $("#inputText").val();
alert(num);
var inputText = encodeURI(encodeURI(num)); 
$("#inputText").val(inputText);
alert($("#inputText").val());
})
})
</script>
<h1>
首页
</h1>
<center>
<form
style="text-align: center; padding-left: 350px; padding-bottom: 250px;"
id="form" method="post" action="SelectAction"
style="text-align: center"> <table>
<tbody>
<tr>
<td>
<b>请输入查询内容:</b>
</td>
<td>
<input type="text" name="inputText6" id="inputText"></input>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" value="查询" id="submit"></input>
<input type="reset" value="重置" id="reset"></input>
</td>
</tr>
</tbody>
</table>
</form> </center>
<br id="endmain" />
</div> <!-- ======== Footer ======== --> <div id="footer">
<hr />
Copyright &copy; 2010, uestc. All rights reserved.
<br /> This web site is maintained by
<a href="mailto:">uestc</a>. Last modified: 18th July, 2011.
</div>
</body>
</html>后台的Action如下:package com.infoIntergrate.ui;import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;public class SelectAction extends ActionSupport {
private String inputText6;
  public String getInputText6(){
return inputText6;
} public void setInputText6(String inputText6) {
this.inputText6 = inputText6;

} public String execute() {

if (inputText6 != null) 
{
try { ActionContext.getContext().getSession().put("inputText",
inputText6);
ActionContext.getContext().getSession().put("result", result);
} catch (Exception e) {
e.printStackTrace();
}
return "success";
} else
return "fail";
}
public static void main(String[] args) {
SelectAction a=new SelectAction();
String inputText6="546成都4884";
a.execute();
}
}

解决方案 »

  1.   

    你的action 和工程的编码集是否是 GBK 即编码集是否统一还有你这是post 方式的提交 为什么在submit的时候 
    var inputText = encodeURI(encodeURI(num)); 还有转码?
      

  2.   

    谢谢回复。
    这是解决问题时候用的一个办法。最后问题解决了,把前台设成utf8编码,后台gbk。问题就这样解决,虽然依旧不解,但也没有心情深究了。
    不大的问题,却被人逼得想吐。心太累,很久不淡定不冷静了。