Класс действий (
Код: Выделить всё
FileUploadActionКод: Выделить всё
package com.caveofprogramming.actions;
import java.io.File;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
public class FileUploadAction extends ActionSupport{
private File fileUpload;
private String fileUploadContentType;
private String fileUploadFileName;
public String getFileUploadContentType() {
return fileUploadContentType;
}
public void setFileUploadContentType(String fileUploadContentType) {
this.fileUploadContentType = fileUploadContentType;
}
public String getFileUploadFileName() {
return fileUploadFileName;
}
public void setFileUploadFileName(String fileUploadFileName) {
this.fileUploadFileName = fileUploadFileName;
}
public File getFileUpload() {
return fileUpload;
}
public void setFileUpload(File fileUpload) {
this.fileUpload = fileUpload;
}
@Action( value = "/fileUpload",
results={@Result(name="success",location="/success.jsp"),
@Result(name="error",location="/error.jsp"),
@Result(name="input",location="/error.jsp")
},
interceptorRefs={
@InterceptorRef(
params={"allowedTypes","image/jpeg,image/jpg,application/zip",
"maximumSize","1024000"},
value="fileUpload"
),
@InterceptorRef("defaultStack"),
@InterceptorRef("validation")
}
)
public String execute(){
try{
return SUCCESS;
} catch(Exception e){
return ERROR;
}
}
public String display() {
return NONE;
}
}
Код: Выделить всё
error.jspКод: Выделить всё
Код: Выделить всё
Success.jspКод: Выделить всё
Insert title here
Success
Код: Выделить всё
fileUpload.jspКод: Выделить всё
Struts 2 <s:file> file upload example
Код: Выделить всё
"Content-Type not allowed: fileUpload "photography-104a.jpg" "upload_37fbf440_169b_4687_af65_93c8c967256c_00000000.tmp" image/pjpeg"
Подробнее здесь: https://stackoverflow.com/questions/255 ... n-struts-2
Мобильная версия