春季文件上传内部服务器错误 [英] Spring File Upload Internal server error

查看:168
本文介绍了春季文件上传内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用spring mvc上传一个文件。我的表单:

 < form enctype =multipart / form-data> 
名称:< input type =textname = name>< br>
电子邮件ID:< input type =emailname = emailID>< br>
附件:< input type =filename = file id =file>< br>
提交?:< input type =submitname = submit value =Done>< br>
< / form>

我得到一个内部服务器错误。



错误是:
$ b $ 1错误

2)没有堆栈跟踪



表单重置本身,而不是进入下一页,这是一个通知页面。

解决方案 html401 / interact / forms.html#h-17.13.1rel =nofollow>一路丢失字符,因为只有ASCII被支持。

 < form enctype =multipart / form-datamethod =POST> 

确定您有 Spring正确配置了文件上传,这意味着你已经设置了一个 MultipartResolver ,没有它Spring不会支持文件上传。



你的控制器应该使用数据绑定,而不是自己做(使用框架)。

  @RequestMapping(value =/ add,params =submit,method = RequestMethod。 POST)
public ModelAndView addForm(@ModelAttribute PostModel newPost){
System.out.println(Added+ newPost.getQuestion()+successfully);
System.out.println(添加文件+ file.getName()+successful);
return addController.showNotice(newPost.getQuestion());
}


I'm trying to upload a file using spring mvc. My form:

    <form enctype="multipart/form-data">
       Name: <input type="text" name=name><br> 
       Email ID: <input type="email" name=emailID><br> 
       Attachment: <input type="file" name=file id="file"><br> 
       Submit?: <input type="submit" name=submit value="Done"><br>
    </form>

I get an internal server error.

The error is:

1)505 Error

2)No Stack Trace

The form resets itself rather than go to the next page which is a notice page.

解决方案

To be safe you should always use POST or PUT when doing uploads else you are going to lose characters along the way as only ASCII is supported then.

<form enctype="multipart/form-data" method="POST">

Make sure that you have Spring configured correctly for file uploads, meaning that you have setup a MultipartResolver, without it Spring is not going to support file uploads.

Your controller should use data-binding, instead of doing it yourself (use the framework).

@RequestMapping(value = "/add", params = "submit", method = RequestMethod.POST)
public ModelAndView addForm(@ModelAttribute PostModel newPost){
    System.out.println("Added " + newPost.getQuestion() + " successfully");
    System.out.println("Added the file " + file.getName() + "successfully");
    return addController.showNotice(newPost.getQuestion());
}

这篇关于春季文件上传内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆