Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 1017|回复: 0

SSH页面回发数据乱码难题!!!

[复制链接]

该用户从未签到

发表于 2011-10-29 08:16:18 | 显示全部楼层 |阅读模式
弄了两天还是没有弄好。。。拜托各位大虾,大姐帮帮忙。。。

struts2配置
<constant name="struts.i18n.encoding" value="GBK" />  

web配置
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
(自己的filter)
  <filter>
  <filter-name> myFilter</filter-name>
  <filter-class>com.DRP.filter.MyFilter</filter-class>
  <init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
  </filter>
<filter-mapping>
<filter-name>myFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>  


html编码
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />  

eclipse编码:GBK

MySQL:GBK

PS:页面回传数据解析是用js,jquery写的
$(document).ready(
function(){


//addEmp.html
$("#phoneA").blur(
function(){
var conditions = "from Department";
var request = {
"conditions" : conditions,
"operation" : "query"
};
//alert("operation is "+request.operation);
$.ajax({
url:"adminDepart.action",
dataType:"json",
cache : false,
data : request,
error : function(textStatus,errorThrown){
alert(errorThrown);
},
success:function(data,textStatus){
var rows = data.results;
var str = "<option value='default'>请选择部门</option>";
for(var i = 0; i<rows.length;i++){
text = rows.department.name;
value = rows.department.id;
str += "<option value='"+value+"'>"+text+"</option>";
}
$("#departmentEmpA").html(str);

}
});
});
$("#departmentEmpA").change(
function(){
var depart = document.getElementById("departmentEmpA");
var departIndex = depart.selectedIndex;
var departName = depart.options[departIndex].text;
var conditions = "from Position as p where p.departName = '"+departName+"'";
var request = {
"posit.departName":departName,
"conditions" : conditions,
"operation" : "query"
};
//alert("operation is "+request.operation);
$.ajax({
url:"adminPosition.action",
dataType:"json",
cache : false,
data : request,
error : function(textStatus,errorThrown){
alert(errorThrown);
},
success:function(data,textStatus){
var rows = data.results;
var str = "<option value='default'>请选择职位</option>";
for(var i = 0; i<rows.length;i++){
text = rows.department.name;
value = rows.department.id;
str += "<option value='"+value+"'>"+text+"</option>";
}
$("#departmentEmpA").html(str);

}
});
});
$("#submit").click(
function(){
var name = document.getElementById("empNameA");
var num = document.getElementById("empNumA");
var cfpw = document.getElementById("cfmPwdA");
var email = document.getElementById("emailA");
var phone = document.getElementById("phoneA");

var depart = document.getElementById("departmentEmpA");
var posit = document.getElementById("positionEmpA");
var positIndex = posit.selectedIndex;
var departIndex = depart.selectedIndex;
var departName = depart.options[departIndex].value;
var posittName = posit.options[positIndex].value;

if(name!="" && num!="" && cfpw != "" && departName != "default" && positName != "default"){
if(email==""){
email="some";
}
if(phone==""){
phone = "some";
}
var conditions = "";
var request = {
"emp.name":name,
"emp.number":num,
"emp.password":cfwd,
"emp.email":email,
"emp.phone":phone,
"emp.dpmNo":departName,
"emp.pstNo":positName,
"conditions":conditions,
"operation":"add"
};
$.ajax({
url:"",
type:&quotOST",
dataType:"json",
data: request,
cache : false,
error:function(textStatus,errorThrown){
alert(errorThrown);
},
success:function(data,textStatus){
if(data.flag != false){
alert("添加成功!!");
}else{
alert("添加失败!!");
}
}
});

}
});



//adminModify.html
$("#queryEmpM").click(
function(){
var num = document.getElementById("empNumM").value;
var name = document.getElementById("empNameM").value;
var otherCondits = docuement.getElementById("conditionM").value;
var request ={
"emp.name":name,
"emp.number":num,
"conditions"therCondits,
"operation":"query"
};
if(!(num=="" && name=="" && otherCondits =="")){
$.ajax({
url:"",
type:"POST",
dataType:"json",
data: request,
cache : false,
error:function(textStatus,errorThrown){
alert(errorThrown);
},
success:function(data,textStatus){

}
});
}
});

});


请求的方法:
public String employeeOperation() throws JSONException, UnsupportedEncodingException{
request.setCharacterEncoding("GBK");
System.out.println("---------here is employeeOperation()!!!------------");
String conditions = request.getParameter("conditions");
System.out.println("here is conditions ===========>>>>>>>"+conditions);
String operation = request.getParameter("operation");
System.out.println(operation);
System.out.println("emp.getName() ===================== "+emp.getName());
System.out.println("emp.getNumber() ================== "+emp.getNumber());
System.out.println("emp.getPhone() ======================"+emp.getPhone());
String encode = request.getCharacterEncoding();
System.out.println(" request.getCharacterEncoding();===================>>>>>>>>>>>>>++++++++"+encode);


if(operation.equals("add")){
if(emp!=null){
beans.add(emp);
flag = empServ.addEmp(beans);
}
}else{

}
return "success";
}

html页面:

<script type="text/javascript" src="../../js/linkTo.js"></script>
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../js/styleChange.js"></script>
<link rel="stylesheet" href="../../css/initialUI.css"></link>
<style>
#btnSet iframe{
width: 75px;
height : 220px;
}
</style>

<div id="btnSet">
<table class="table2">
<tr>
<td>
<input id="addEmp" type="button" class="btn1" onclick="linkTo('addEmp',document.getElementById('panel'));" value="增加用户"/>
</td>
<td>
<input id="modifyEmp" type="button" class="btn1" onclick="linkTo('modifyEmp',document.getElementById('panel'));" value="修改用户">
</td>
<td>
<input id="queryEmp" type="button" class="btn1" onclick="linkTo('queryEmp',document.getElementById('panel'));" value="查询用户">
</td>
<td>
<input id="deleteEmp" type="button" class="btn1" onclick="linkTo('delEmp',document.getElementById('panel'));" value="删除用户">
</td>
</tr>
</table>
</div>

<div>
   
<iframe id="panel" src="" width="550" height="400"></iframe>

</div>
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

GMT+8, 2024-5-4 10:06 , Processed in 0.395508 second(s), 46 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表