Java 在JQuery文件上载程序中获取异常
我是JQuery文件上传程序的新手,我正在实现其中的一些部分。当我从JQuery file uploader中选择图像时,会调用服务器端(SpringController),但API返回: 406不可接受 这是我对服务器的呼叫:Java 在JQuery文件上载程序中获取异常,java,jquery,file-upload,jquery-file-upload,jhipster,Java,Jquery,File Upload,Jquery File Upload,Jhipster,我是JQuery文件上传程序的新手,我正在实现其中的一些部分。当我从JQuery file uploader中选择图像时,会调用服务器端(SpringController),但API返回: 406不可接受 这是我对服务器的呼叫: $(this).fileupload({ // Uncomment the following to send cross-domain cookies: //xhrFields: {withCredentials: true},
$(this).fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: uploadSettings.upload_url,
type: 'POST',
maxNumberOfFiles: uploadSettings.maxNumberOfFiles,
maxFileSize: uploadSettings.maxFileSize,
acceptFileTypes: uploadSettings.fileSelection,
sequentialUploads: true,
paramName:'uploadfiles[]',
dataType: 'text'
});
我的Java控制器代码如下:
@RequestMapping(value = { "/user/fileuploader" }, method = RequestMethod.POST,
produces = "text/plain")
@ResponseBody public String uploadFileHandler(
@RequestParam("uploadfiles[]") MultipartFile[] file,
HttpServletRequest request, HttpServletResponse response) {
有什么建议吗?这里有一个项目,它使用与JHipster非常相似的堆栈(我是这两个项目的作者),并使用相同的JQuery插件进行上传: 正如你所看到的,我的返回对象是不同的。您可以从以下位置复制我的代码:
您的后端服务告诉您,它返回的响应类型未在客户端请求的Accept type HTTP头中提供。参考:1.找出服务2返回的响应(内容类型)。在请求接受标头中提供此响应(内容类型)。->406您的意思是需要描述内容类型:“多部分/表单数据”和url。我从控制器返回的响应是文本/纯文本,我在数据“text”中描述了它。我的accept类型是“accept text/plain,/;q=0.01”,谢谢回复。但是我使用的是.html页面,所以我无法使用jstl标记。页面转到404。您有新的URL吗?原始参考: