弄了两天还是没有弄好拜托各位大虾,大姐帮帮忙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>
<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>
解决方案 »
- xml解析的问题,很郁闷......
- tablesorter插件,怎么让一列不变
- 有关session的问题,高分!!!代码!
- javaWEB 开发的安全问题~请列举~
- 连接数据库出错!都弄了两天了
- 征服Ajax Web2.0开技术详解 求全本PDF。。。在线等
- jsp和asp.net谁的运行效率高?
- 新人请教 struts2 上传中途怎样取消上传
- 怎样取一个字符串的前3位,怎么从第5位取共取8位?
- 一个关于servlet叶面控制权跳转的问题,急
- 求助:小弟学java 框架不怎么懂,年底又要找工作了,不知道找哪方面的工作,请前辈提点建议吧
- struts2-convention-plugin 与intercepter问题
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="GBK"/>