qq_24642453 2017-09-06 17:25 采纳率: 0%
浏览 955
已结题

SSH2 框架 文件上传不了问题

之前报struts.multipart.saveDir错误,配置过后不报错了,但也上传不了文件了,现在完全蒙圈了
action代码,action配置是最简单配置,这是别人的代码,我拿过来测试的,自己项目跟这个差不多,情况也一样

public class FileUploadAction extends ActionSupport{
private File image;
//获得文件的文件名,格式为:nameFileName,这里格式中的name为jsp页面中的name属性
private String imageFileName;

public String getImageFileName() {
    return imageFileName;
}
public void setImageFileName(String imageFileName) {
    this.imageFileName = imageFileName;
}
public File getImage() {
    return image;
}
public void setImage(File image) {
    this.image = image;
}

public String execute() throws Exception{
    //获得要存放图片的绝对路径
    String realpath = ServletActionContext.getServletContext().getRealPath("/user/usericon");
    System.out.println(realpath);
    //在路径下创建上传的文件
    File savefile = new File(new File(realpath),imageFileName);
    if(image!=null){
        if(!savefile.getParentFile().exists()){
            //如果路径不存在,则创建一个
            savefile.getParentFile().mkdirs();
            //把上传的文件保存在路径中
            FileUtils.copyFile(image, savefile);
            ActionContext.getContext().put("message", "上传成功");
            System.out.println("上传成功");
            return "seccuss";
        }
    }else{
        System.out.println("文件为空");
        return "error";
    }
    return "error";
}
public String getfile(){
    System.out.println(imageFileName);
    return "error";
}

}

jsp代码

  
        文件:  
          
      
  • 写回答

2条回答

  • Tsui丶 2017-09-07 00:42
    关注

    断点调试下 看下是哪里的问题,估计是获取不到前台信息是吧,那么应该是前台文件没有传过来,猜你是表单提交,然后没有写enctype="multipart/form-data"

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog