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 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名