这个是还未上传时的界面: 这个是上传完成时的界面: 就是不知道为什么取不到界面 这个是jsp的代码 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> nbsp;HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script></script>
<script> <br /> var id=0; <br /> var i = 0; <br /> function addressAction(){ <br /> $.post( <br /> './upload/progress.action', <br /> function(data){ <br /> if(data.currentItem==0){ <br /> $("#message").text('0%'); <br /> }else if(data.state.rate<=100){ <br /> SetProgress(data.state.rate); <br /> }else{ <br /> $("#message").html("100% 上传完成!").fadeIn("slow");//加载完毕提示 <br /> window.clearInterval(id); <br /> } <br /> $("#img").html(""); <br /> var num=data.state.rate/10; <br /> <br /> for(var i=1;i<=num;i++){ <br /> $("#img").append("<img src='./images/grid.gif' / alt="Struts2文件上传,加进度条这个功能我是实现了,但是为何我取不到Struts2的返回值,兄弟们帮我看下_html/css_WEB-ITnose" >"); <br /> } <br /> for(var j=1;j<=10-num;j++){ <br /> $("#img").append("<img src='./images/gray.gif' / alt="Struts2文件上传,加进度条这个功能我是实现了,但是为何我取不到Struts2的返回值,兄弟们帮我看下_html/css_WEB-ITnose" >"); <br /> } <br /> }, <br /> 'json' <br /> ); <br /> } <br /> var progress_id = "loading"; <br /> function SetProgress(progress) { <br /> if (progress) { <br /> $("#" + progress_id + " > div").css("width", String(progress) + "%"); //控制#loading div宽度 <br /> $("#" + progress_id + " > div").html(String(progress) + "%"); //显示百分比 <br /> } <br /> } <br /> <br /> function submitForm(){ <br /> if($("#f1").val()==""){ <br /> alert('上传文件为空!!!'); <br /> return ; <br /> } <br /> id=window.setInterval(addressAction,10); <br /> $("form:first").submit();/*提交第一个表单*/ <br /> } <br /> </script>
enctype="multipart/form-data" target="hidden_frame">
File:
上传进度条的action
public class FileProgressAction extends ActionSupport {
private State state;
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
@Override
public String execute() throws Exception {
HttpSession session = ServletActionContext.getRequest().getSession();
this.state = (State) session.getAttribute("state");
if(state==null){
System.out.println("action is null");
state = new State();
state.setCurrentItem(0);
}else{
Double a=Double.parseDouble(state.getReadedBytes()+"");
Double b=Double.parseDouble(state.getTotalBytes()+"");
double result=a/b*100;
state.setRate((int)result);
}
return SUCCESS;
}
}
上传完成的action 返回值就在这里
public class FileProgressUploadAction extends ActionSupport{
private File file;
private String fileFileName;
private String fileContentType;
private String flag="===============";
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
@Override
public String execute(){
try {
System.out.println("file:"+file);
InputStream is=new FileInputStream(file);
String root=ServletActionContext.getRequest().getRealPath("/upload");
System.out.println("root:"+root);
System.out.println("name:"+this.fileFileName);
System.out.println("type:"+this.fileContentType);
File destFile=new File(root,this.fileFileName);
OutputStream os=new FileOutputStream(destFile);
byte [] b=new byte[1024*1024*10];
int length=0;
while(true){
length=is.read(b);
if(length break;
os.write(b,0,length);
}
setFlag("SUCCESS");
is.close();
os.close();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("=====================");
return SUCCESS;
}
}
帖子比较长希望好心人帮我看看吧,想了好久没找出什么原因
回复讨论(解决方案) 这个是struts.xml 配置文件 /index.jsp /error.jsp name="requestParser" class="com.zjg.listtener.MyMultiPartRequest" scope="default" optional="true" />