弄了两天还是没有弄好拜托各位大虾,大姐帮帮忙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编码:GBKMySQL:GBKPS:页面回传数据解析是用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[i].department.name;
value = rows[i].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[i].department.name;
value = rows[i].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:"POST",
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":otherCondits,
"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>

解决方案 »

  1.   

    些这么多filter干什么,用spring的就可以了。还有跟你数据库的编码一致不?
      

  2.   

    写这么多filter干什么,用spring的就可以了。还有跟你数据库的编码一致不?
      

  3.   

    弄这么多filter干什么,用spring的就可以了。还有跟你数据库的编码一致不?
      

  4.   

    项目中如果使用Ajax的话,就统一采用utf-8.如果没有使用Ajax,就统一采用gbk
      

  5.   

    我用了ajax,可是如果改为utf8我又要改动几十张网页,有没有更具体一点的做法
      

  6.   

    另外数据库的编码,eclipse,页面编码都是gbk,从数据库查询出来到页面显示没有问题,但是页面回传到服务器就出问题了,tomcat的编码我也改成gbk的了,不知道问题出在哪里
      

  7.   

    到你的服务器里面的服务文件  改动你的服务器编码  比如我的是tomcat服务器 我就改动apache-tomcat-6.0.28\conf \server.xml 中
     <Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" URIEncoding="GBK"/>
      

  8.   

    用工具把整个项目编码改成GBK试试。。把所有文件的编码都用GBK格式
      

  9.   

    我用utf-8比较多,没乱码过。乱码的话页面重新编译就好额