使用ext+struts2做一个文件上传,但是后台接受的汉字全为?????,如果把struts.xml中<constant name="struts.i18n.encoding" value="utf-8" />的utf-8改成gbk就不出现乱码,但是其他操作则出现乱码(例如增加操作),该怎么办呢?
// 导入html信息
下面是代码 请高手赐教
function inputHtml(){ var textName=new Ext.form.TextField({
fieldLabel:'提取人姓名',
name:'name',
width :160,
id:'nameid',
allowBlank:false
});
var txtEncoding=new Ext.form.ComboBox({
fieldLabel : "编码规则",
width :160,
readOnly : true,
typeAhead : true,
allowBlank:false,
editable : false,
name : 'encoding',
// hiddenName:'encoding',//真实获取值
id:'encodingid',
mode : "local",
store : new Ext.data.SimpleStore({
fields : ["encodingvalue", "encodingtext"],
data : [["1", "gbk"], ["2", "utf-8"]]
}),
valueField : "encodingvalue",
displayField : "encodingtext",
triggerAction : "all",
selectOnFocus : true
});
var txtStateName=new Ext.form.ComboBox({
fieldLabel : "网站名称",
readOnly : true,
typeAhead : true,
editable : false,
name : 'stateName',
// hiddenName:'stateName',获取真实的值
allowBlank:false,
id:'stateNameid',
width :160,
mode : "local",
store : new Ext.data.SimpleStore({
fields : ["stateNamevalue", "stateNametext"],
data : [["1", "我爱我家"], ["2", "好租网"]]
}),
valueField : "stateNamevalue",
displayField : "stateNametext",
triggerAction : "all",
selectOnFocus : true
});
var txtDrawName=new Ext.form.ComboBox({
fieldLabel : "抽取方式",
readOnly : true,
typeAhead : true,
width :160,
editable : false,
name : 'drawOff',
// hiddenName:'drawOff',//获取真实的值
allowBlank:false,
id:'drawOffid',
mode : "local",
store : new Ext.data.SimpleStore({
fields : ["drawOffvalue", "drawOfftext"],
data : [["1", "简单信息"], ["2", "具体信息"]]
}),
valueField : "drawOffvalue",
displayField : "drawOfftext",
triggerAction : "all",
selectOnFocus : true
});
var txtResource=new Ext.form.TextField({
xtype: 'textfield',
fieldLabel: '文件名',
allowBlank:false,
name: 'file',
id:'fileid',
width :200,
inputType: 'file'// 文件类型
});
var txtDateTime=new Ext.form.DateField({
fieldLabel : "提取时间",
readOnly : true,
width :160,
allowBlank:false,
format : 'Y-m-d',
id:'dateTimeid',
name:'dateTime'
});
form6=new Ext.form.FormPanel({
frame:true,
id:'uploadForm',
baseCls: 'x-plain',
labelWidth: 75,
labelAlign : 'right',
fileUpload:true, // 需上传文件
method:'POST',
enctype:'multipart/form-data',
items:[textName, txtEncoding,txtStateName,txtResource,txtDrawName,txtDateTime],
buttons:[{
text:"提取信息",
handler:function(){
plickUp();
}
},{
text:'重置',
handler:function(){
form6.getForm().reset();
}
}]
});
win6=new Ext.Window({
title:'导入html',
id:'inputId',
width:'400',
modal:true,
autoHeight:true,
items:[form6]
});
win6.show();
}
form6.getForm().submit( {
url : 'acquireNews.do',
method:'post',
// 修改
waitTitle : '请稍候',
waitMsg : '正在提交表单数据,请稍候...',
success : function(f, action) {
if (action.result.success) {
Ext.Msg.alert('消息', action.result.msg, function() {
win6.close();
grid.getStore().reload();
// addStudentform.getForm().reset();
// form.buttons[0].setText('添加');
});
}
},
failure : function() {
Ext.Msg.alert('错误', "添加失败");
}
});
// 导入html信息
下面是代码 请高手赐教
function inputHtml(){ var textName=new Ext.form.TextField({
fieldLabel:'提取人姓名',
name:'name',
width :160,
id:'nameid',
allowBlank:false
});
var txtEncoding=new Ext.form.ComboBox({
fieldLabel : "编码规则",
width :160,
readOnly : true,
typeAhead : true,
allowBlank:false,
editable : false,
name : 'encoding',
// hiddenName:'encoding',//真实获取值
id:'encodingid',
mode : "local",
store : new Ext.data.SimpleStore({
fields : ["encodingvalue", "encodingtext"],
data : [["1", "gbk"], ["2", "utf-8"]]
}),
valueField : "encodingvalue",
displayField : "encodingtext",
triggerAction : "all",
selectOnFocus : true
});
var txtStateName=new Ext.form.ComboBox({
fieldLabel : "网站名称",
readOnly : true,
typeAhead : true,
editable : false,
name : 'stateName',
// hiddenName:'stateName',获取真实的值
allowBlank:false,
id:'stateNameid',
width :160,
mode : "local",
store : new Ext.data.SimpleStore({
fields : ["stateNamevalue", "stateNametext"],
data : [["1", "我爱我家"], ["2", "好租网"]]
}),
valueField : "stateNamevalue",
displayField : "stateNametext",
triggerAction : "all",
selectOnFocus : true
});
var txtDrawName=new Ext.form.ComboBox({
fieldLabel : "抽取方式",
readOnly : true,
typeAhead : true,
width :160,
editable : false,
name : 'drawOff',
// hiddenName:'drawOff',//获取真实的值
allowBlank:false,
id:'drawOffid',
mode : "local",
store : new Ext.data.SimpleStore({
fields : ["drawOffvalue", "drawOfftext"],
data : [["1", "简单信息"], ["2", "具体信息"]]
}),
valueField : "drawOffvalue",
displayField : "drawOfftext",
triggerAction : "all",
selectOnFocus : true
});
var txtResource=new Ext.form.TextField({
xtype: 'textfield',
fieldLabel: '文件名',
allowBlank:false,
name: 'file',
id:'fileid',
width :200,
inputType: 'file'// 文件类型
});
var txtDateTime=new Ext.form.DateField({
fieldLabel : "提取时间",
readOnly : true,
width :160,
allowBlank:false,
format : 'Y-m-d',
id:'dateTimeid',
name:'dateTime'
});
form6=new Ext.form.FormPanel({
frame:true,
id:'uploadForm',
baseCls: 'x-plain',
labelWidth: 75,
labelAlign : 'right',
fileUpload:true, // 需上传文件
method:'POST',
enctype:'multipart/form-data',
items:[textName, txtEncoding,txtStateName,txtResource,txtDrawName,txtDateTime],
buttons:[{
text:"提取信息",
handler:function(){
plickUp();
}
},{
text:'重置',
handler:function(){
form6.getForm().reset();
}
}]
});
win6=new Ext.Window({
title:'导入html',
id:'inputId',
width:'400',
modal:true,
autoHeight:true,
items:[form6]
});
win6.show();
}
form6.getForm().submit( {
url : 'acquireNews.do',
method:'post',
// 修改
waitTitle : '请稍候',
waitMsg : '正在提交表单数据,请稍候...',
success : function(f, action) {
if (action.result.success) {
Ext.Msg.alert('消息', action.result.msg, function() {
win6.close();
grid.getStore().reload();
// addStudentform.getForm().reset();
// form.buttons[0].setText('添加');
});
}
},
failure : function() {
Ext.Msg.alert('错误', "添加失败");
}
});
这里改成UTF-8
统一编码,所有的地方均改成UTF-8试试...
Eclipse修改JAVA,JSP,JS文件编码
JSP中
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>2.修改EXT请求编码
defaultPostHeader:"application/x-www-form-urlencoded; charset=utf-8"
可在JS页面修改,或者直接修改ext-base-debug.js/ext-base.js中默认3如果有filter 修改WEB.XML中的filter 编码,如: <filter>
<filter-name>character encoding filter</filter-name>
<filter-class>web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
4修改strut2的编码
struts.properties文件中 修改
struts.locale=zh_CN
struts.i18n.encoding=utf-8
没有直接加上
如果都统一了,是没问题的response的返回如果是JSON
response.setContentType("text/json; charset=UTF-8");