Struts2文件上传,加进度条这个功能我是实现了,但是为何我取不到Struts2的返回值,兄弟们帮我看下_html/css_WEB-ITnose
程序员文章站
2022-04-26 16:15:59
...
这个是还未上传时的界面:
这个是上传完成时的界面:
就是不知道为什么取不到界面
这个是jsp的代码
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
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;
}
}
帖子比较长希望好心人帮我看看吧,想了好久没找出什么原因
这个是上传完成时的界面:
就是不知道为什么取不到界面
这个是jsp的代码
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
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 配置文件
scope="default" optional="true" />
上一篇: css阴影效果的实现_html/css_WEB-ITnose
下一篇: 用ps怎么修改原图数字?