前端文件及相关信息上传代码
var formdata=new FormData();
formdata.append("file",file);
formdata.append("buildid",this.buildingData.attributes.objectid);
formdata.append("filetype",fileType);
formdata.append("filename",file.name);
var req = new XMLHttpRequest();
req.open("POST", "../client/service/comPetingDataController/upLoadFiles", true);
req.send(formdata);
req.onload = lang.hitch(this,function(result){
console.log(result);
})
后台数据接收代码如下
@At("/upLoadFiles")
@GET
@POST
@Ok("json")
@AdaptBy(type = VoidAdaptor.class)
public String upLoadFiles(HttpServletRequest request, HttpServletResponse response,@Param("filename") String filename){
System.out.println(filename);
JSONObject res = new JSONObject();
try {
Integer buildid = comPetingDataService.upLoadFiles(request);
res.put("success", true);
res.put("message", "成功上传图片信息");
res.put("buildid", buildid);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
res.put("success", false);
res.put("message", e.toString());
}
return res.toString();
}
这里面通过@Param("filename") String filename 或request.getParameter("filename")都无法获得参数
但是如果服务器是tomcat8就没问题,不知道是nutz的原因还是tomcat版本的问题