Struts2+Ext2+jsonplugin文件上传成功后,出现下载页面的问题

top3372 2008-08-19 01:03:27
服务器Struts2 + jsonplugin , interceptor fileUploadStack ,

在Ext.form.FormPanel 中 设置了 fileUpload = true ;

上传文件时 ,能上传成功,
不过结果返回时总提示要下载文件,而不是 执行 success 或者 failure 函数。

已经在struts.xml里加上了<param name="contentType">text/html</param>
但还是要下载文件

jsonplugin 返回的数据为 { “success”:true}
而我看别人有的写{success:true} 没有引号,不知是怎么返回的


给出我的源代码,各位帮我查查错误

能否发一份Struts2+Ext2+jsonplugin文件上传的源代码
我的邮箱top3372@163.com

Action的代码
package com.ml.web.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.struts2.ServletActionContext;

import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;

public class Ext2UploadAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -8217750317798955984L;

private File file1;


private String file1ContentType;
private String file1FileName;

private String savePath1;

private boolean jsonString;

@JSON(name="success")
public boolean getJsonString() {
return jsonString;
}

public void setJsonString(boolean jsonString) {
this.jsonString = jsonString;
}

public File getFile1() {
return file1;
}

public void setFile1(File file1) {
this.file1 = file1;
}


public String getFile1ContentType() {
return file1ContentType;
}

public void setFile1ContentType(String file1ContentType) {
this.file1ContentType = file1ContentType;
}

public String getFile1FileName() {
return file1FileName;
}

public void setFile1FileName(String file1FileName) {
this.file1FileName = file1FileName;
}

public String getSavePath1() {
return ServletActionContext.getRequest().getRealPath(savePath1);
}

public void setSavePath1(String savePath1) {
this.savePath1 = savePath1;
}

public String execute()throws Exception{
String fileName = getFile1FileName();
try{
if(!(new File(getSavePath1()).isDirectory()))
{
new File(getSavePath1()).mkdir();
}
}
catch(SecurityException e)
{
this.LOG.debug(e.getMessage());
}
FileOutputStream fos = new FileOutputStream(getSavePath1() + "/" + fileName);
FileInputStream fis = new FileInputStream(getFile1());
byte[] buffer = new byte[1024];

int len = 0;
while((len = fis.read(buffer)) > 0){
fos.write(buffer,0,len);
}
fis.close();
fos.close();
this.jsonString = true;;

return SUCCESS;

}
}


struts的配置
<?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="ext2" extends="json-default" >
<action name="ext2Upload" class="com.ml.web.action.Ext2UploadAction">
<param name="savePath1">/upload</param>
<result name="success" type="json">
<param name="excludeProperties">file1,file1ContentType,file1FileName,savePath1</param>
<param name="exportVars">success</param>
<param name="contentType">text/html</param>
</result>
</action>
</package>
</struts>


js文件
    Ext.onReady( function (){   
var form = new Ext.form.FormPanel({
labelAlign: 'right',
title: 'form',
labelWidth: 50,
frame:true,
fileUpload: true,
url:" ext2Upload.action",
width: 380,

items: [{
xtype: 'textfield',
fieldLabel: '文本框',
name: 'file1',
inputType: 'file'//文件类型
}],
buttons: [{
text: '保存',
handler: s
}]
});
function s() {
form.getForm().submit({//客户端的数据提交给服务器
waitTitle:"请稍候",
waitMsg:"正在提交表单数据,请稍候。。。。。。",
//如果submit失敗,執行這一個function
failure:function(){
Ext.MessageBox.hide();
Ext.MessageBox.alert('Error','失败');
},
success: function(){
Ext.MessageBox.hide();
Ext.MessageBox.alert('Success','成功');
}
});
}

form.render("fileUpload");

});


jsp文件

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
href="ext/resources/css/ext-all.css" />

<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>

<script type="text/javascript" src="ext/ext-all.js"></script>
<script type="text/javascript" src="ext/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/upload.js"></script>
</head>

<body>
<div id="fileUpload"></div>
</body>
</html>


...全文
465 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiusongze 2009-12-10
  • 打赏
  • 举报
回复
请问您的这个问题解决了吗,解决的话能不能给俺说说qiusz@bankcomm.com,谢谢啊
zzw0598 2009-01-09
  • 打赏
  • 举报
回复
跟楼主同样的问题。 请问解决了吗?
yougucao379548695 2008-08-24
  • 打赏
  • 举报
回复
楼主你好哈。我想问下你的系统在ie下提交时中午会出现乱码吗?我在ff下是正常的。。你的问题我帮你看看哈。
谢谢啦!

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧