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

解决方案 »

  1.   

      如果不用s的标签 那就用input type="file"  做上传一样的
      

  2.   

     网上很多 上传下载啊。自己搜啊。 什么ajax 上传,基于servlet上传。
      

  3.   

    不用标签也一样的呀
    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.javapublic 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);
    if (!savefile.getParentFile().exists())
    savefile.getParentFile().mkdirs();
    FileUtils.copyFile(image, savefile);
    this.filePath = "images/" + imageFileName;
    ActionContext.getContext().put("message", "文件上传成功");
    }
    return UploadAction.SUCCESS;
    }
    }
      

  4.   

    <s:form action="upload" enctype="multipart/form-data" method="post">
       <s:textfield name="title" label="文件标题" />
       <s:file name="upload" label="文件选择"/>
       <s:submit value="上传" />
       </s:form>
      

  5.   

    其实用不用都一样,具体可以看看页面的input源代码,http://blog.csdn.net/chenghui0317/article/details/9531879