• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

strust2上传文件空指针异常

刚学Struts2,按照书上原模原样的敲的代码,本来可以上传文件的,后来我加了手动文件过滤功能,后来又注释掉了,然后就不行了,报空指针异常! 这是显示的错误
032002uab668ldsbnl68lc.jpg

这是Action里的代码
public class UploadAction extends ActionSupport {    private String title; //封装上传文件标题的成员变量    private File upload; //封装上传文件域的成员变量    private String uploadContentType; / /封装上传文件类型的成员变量    private String uploadFileName;// 封装上传文件名字的属性    private String savePath;    // 接受struts.xml 文件配值的方法    public void setSavePath(String value) {        this.savePath = value;    }    // 获开上传文件的保存位置    private String getSavePath() throws Exception {        return ServletActionContext.getServletContext().getRealPath(savePath);    }    public String getTitle() {        return title;    }/    public void setTitle(String title) {        this.title = title;    }    public File getUpload() {        return upload;    }    public void setUpload(File upload) {        this.upload = upload;    }    public String getUploadContentType() {        return uploadContentType;    }    public void setUploadContentType(String uploadContentType) {        this.uploadContentType = uploadContentType;    }    public String getUploadFileName() {        return uploadFileName;    }    public void setUploadFileName(String uploadFileName) {        this.uploadFileName = uploadFileName;    }    @Override    public String execute() throws Exception {        FileOutputStream fos=new FileOutputStream(getSavePath()+"\\"+getUploadFileName());        FileInputStream fis=new FileInputStream(getUpload());        byte[] buffer= new byte[1024];        int len=0;        while((len=fis.read(buffer))>0){            fos.write(buffer, 0, len);        }        return SUCCESS;    }}这是strusts.xml里的代码
               /uploadFiles              /success.jsp               谢谢各位了!!!!在线等

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

看错误貌似是getSavePath的问题。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!