<s:textfield id="tzid" name="bo.tzid"/>
这是前台jquery 操作,提交数据给action后台处理
//提交操作(添加,删除,修改)
$.getJSON("setProxy!Save.action?"+encodeURI($("form").serialize()),null,function(json){
if(null!=json&&json.length==1&&json[0].opare=="0")
{
$("#tzid").val(json.tzid);
alert("保存成功!"+$("#tzid").val()+"==>>");
EnContrl();
modeRest();
}else if(null!=json&&json.length==1&&json[0].opare!="0")
{
alert("保存失败!");
}
});
这是后台
boo bo; //get,set封装都有 public String doSave() {
int opare = 0;
try {
User user = this.getSessionUser();
if (null != bo.getTzid() && !"".equals(bo.getTzid())) {
this.getDao().edit(bo, user, this.getConn());
} else {
this.getDao().add(bo, user, this.getConn());
}
this.outPrint("[{\"opare\":\"" + opare + "\",\"tzid\":\"" + bo.getTzid() + "\"}]");
}catch(Exception e){}
}
数据库数据中文乱码试了几种方案都不行:
1.queryBean.setName(URIUtil.encodeQuery(queryBean.getName()))
2.new String(str.getBytes("ISO-8859-1"), "gb2312")
3.<constant name="struts.i18.encoding" value="utf-8"></constant>
4.<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="GBK"/>实在是没招了,所以请各位大虾帮忙出一招?
这是前台jquery 操作,提交数据给action后台处理
//提交操作(添加,删除,修改)
$.getJSON("setProxy!Save.action?"+encodeURI($("form").serialize()),null,function(json){
if(null!=json&&json.length==1&&json[0].opare=="0")
{
$("#tzid").val(json.tzid);
alert("保存成功!"+$("#tzid").val()+"==>>");
EnContrl();
modeRest();
}else if(null!=json&&json.length==1&&json[0].opare!="0")
{
alert("保存失败!");
}
});
这是后台
boo bo; //get,set封装都有 public String doSave() {
int opare = 0;
try {
User user = this.getSessionUser();
if (null != bo.getTzid() && !"".equals(bo.getTzid())) {
this.getDao().edit(bo, user, this.getConn());
} else {
this.getDao().add(bo, user, this.getConn());
}
this.outPrint("[{\"opare\":\"" + opare + "\",\"tzid\":\"" + bo.getTzid() + "\"}]");
}catch(Exception e){}
}
数据库数据中文乱码试了几种方案都不行:
1.queryBean.setName(URIUtil.encodeQuery(queryBean.getName()))
2.new String(str.getBytes("ISO-8859-1"), "gb2312")
3.<constant name="struts.i18.encoding" value="utf-8"></constant>
4.<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="GBK"/>实在是没招了,所以请各位大虾帮忙出一招?
解决方案 »
- 大家发送邮件用的是JavaMail吗?
- JSP页面跳转后,分页显示失败,SOS!
- 我在Action中用setXXX()设置了Form里一个属性的值,怎么在jsp页面中取得这个值呢?我用<bean:write name="",property="">得不到值
- 关于JAVABeans的编写 20分的问题
- 为什么ACTIONFORM的VALIDATE()有ERROR返回,ACTION还可以执行EXECUTE()?
- javax.naming.CommunicationException
- 请教:关于java web项目的优化问题
- 如何将JSP中的所有程序打包运行????
- JSP&数据库—结果集&属性&控制?
- 如何把String temp = request.getParameter("id"); 转换为int类型
- Ireport报表在IE中无法显示
- 持续集成
前台通过 $.getJSON( "setProxy!Save.action? "+encodeURI($( "form ").serialize()),null,function(json){
到action里面的时候就是中文乱码
三楼回复:
过滤器全都配制,可就是收到的数据是中文乱码!
在tomact中配制这个
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="GBK" useBodyEncodingForURI="true" />
然后再把JSP页面的编码格式写成GBK,以及页面属性也要改成BGK!这样就行了!
因为我用的struts2集成的,ognl里面自带转码填充的!