EXT+Struct2文件上传出现异常

Action类代码为
public String readexcel() throws Exception {

String path = getRealyPath(uploaddir);
File dir = new File(path);
if (!dir.exists()) {
dir.mkdir();
}
int length = excelfileFileName.length();
int start = excelfileFileName.indexOf('.');
if (!excelfileFileName.substring(start+1, length).equalsIgnoreCase("xls")) {
//String msg = "{\"success\":false,\"file\":'wrongfileaaa文件错误'}";
String a = "aaa文件错误";
String msg = "{\"success\":true,\"msgs\":'" +a+ "'}";
getResponse().setCharacterEncoding("UTF-8");
//getResponse().setContentType("html/text");
getResponse().getWriter().write(msg);
return null;
}else{
BufferedInputStream bis = null;
try {
FileInputStream fis = new FileInputStream(excelfile);
bis = new BufferedInputStream(fis);
Workbook book = Workbook.getWorkbook(bis);
Sheet sheet = book.getSheet(0);
int cols = sheet.getColumns();
int rows = sheet.getRows();
List<String[]> list = new ArrayList<String[]>();
for (int j = 0; j < rows; j++) {
String [] strs = new String[cols];
for (int i = 0; i < cols; i++) {
strs[i] = sheet.getCell(i,j).getContents();
}
list.add(strs);
}
StaffBindDao staff = new StaffBindDao();
//staff.addinfo(tablename, list);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
if (bis!=null) {
bis.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("sssssssssssssssssss");
String msg = "{success:true, file:'a"+excelfileFileName+"!'}";
getResponse().getWriter().write(msg);
return null;
}
}


js代码为
Ext.BLANK_IMAGE_URL = "/abcd/ext/resources/images/s.gif";
Ext.form.Field.prototype.msgTarget = 'side';
Ext.QuickTips.init();
Ext.onReady(function(){
var msg = function(title, msg){
Ext.Msg.show({
title: title,
msg: msg,
minWidth: 200,
modal: true,
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
});
};
var _form = new Ext.FormPanel({
fileUpload: true,
width: 485,
height:285,
frame: true,
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'textfield',
emptyText: '请填写要插入数据表名称',
blankText: '数据表名称为必填写项',
fieldLabel: '数据表',
name:'tablename'
},{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: '请选择文件',
blankText: '必须上传文件',
fieldLabel: '文件',
name: 'excelfile',
buttonCfg: {
text: '',
iconCls: 'upload-icon'
}
}],
buttons: [{
text: '上传',
handler: function(){
if(_form.getForm().isValid()){
_form.getForm().submit({
url: 'back/ReadExcelaction_readexcel.action',
//url:'result.jsp',
waitMsg: '文件正在上传',
success: function(_form, o){
msg('系统提示', '文件内容已被成功加载'+o.result.file);
},
failure:function(_form,o){
msg('系统提示', '文件内容已被成功加载'+o.result.file);
if(o.result.file=='wrongfile')
{
msg('系统提示', '文件类型不正确!');
return;
}
}
});
}
}
},{
text: '取消',
handler: function(){
_form.getForm().reset();
}
}]
});
function test(){
myform.form.submit();
}
var window = new Ext.Window({
title:'Excel 文件的上传',
width:500,
height:143,
items:[_form]
});
window.show();
});


XML配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>

<package name="back" extends="struts-default" namespace="/back">

<action name="*action_*" class="com.jws.action.{1}Action" method="{2}">
<!-- 文件上传 拦截器-->
<!--
<interceptor-ref name="defaultStack">
<param name="fileUpload.maximumSize">102400000</param>

</interceptor-ref>


<result name="test">index.jsp</result>
-->
<param name="uploaddir">/WEB-INF/UploadFiles</param>
<result name="test">../index.jsp</result>

</action>
</package>

</struts>


文件成功上传后
发现一个奇怪的问题。就是上传完成以后,返回的json..
this.responseWrite("{\"success\":true,\"msgs\":'" +uploadFileName+ "'}");
代码里面就这样写的, 可是通过调试,前台多了一个 <per> 标签。 json一直报错,郁闷的很,不知道为什么产生这个东西。
如果设置Response的contentType的话 FF就会出现文件下载的现象
为什么?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值