日期:2014-05-18  浏览次数:20631 次

struts2 不用标签文件上传
发现网上和书上都是带<s:file>的
有没有不带的例子,请分享下,谢谢
struts2

------解决方案--------------------
  如果不用s的标签 那就用input type="file"  做上传一样的
------解决方案--------------------
 网上很多 上传下载啊。自己搜啊。 什么ajax 上传,基于servlet上传。
------解决方案--------------------
不用标签也一样的呀
index.jsp

  <body>
    <form action="uploadAction.action" method="post" enctype="multipart/form-data">
    <input type="file" name="image"><br/>
    <input type="submit" value="上传">
    </form>
    ${message}
  </body>

UploadAction.java

public class UploadAction extends ActionSupport {
private File image;
private String imageFileName;
private String imageContentType;
private String filePath;


public String getFilePath() {
return filePath;
}

public void setFilePath(String filePath) {
this.filePath = filePath;
}

public File getImage() {
return image;
}

public void setImage(File image) {
this.image = image;
}

public String getImageFileName() {
return imageFileName;
}

public void setImageFileName(String imageFileName) {
this.imageFileName = imageFileName;
}

public String getImageContentType() {
return imageContentType;
}

public void setImageContentType(String imageContentType) {
this.imageContentType = imageContentType;
}

@Override
public String execute() throws Exception {
System.out.println("upload");
String realpath = ServletActionContext.getServletContext().getRealPath(
"/images");
if (this.image != null) {
File savefile = new File(new File(realpath), imageFileName);