mky136
mky136
2017-08-07 09:13
采纳率: 18.2%
浏览 6.8k
已采纳

前台报错 415 (Unsupported Media Type)

//异步上传图片 function doploy(){ //定义参数 var options={ url:"rest/process/deploy/", dataType:"text", type:"post", success:function(data){ alert(data); }, error:function(){ alert("upload error"); } }; //使用jquery.form异步上传图片 $("#deployProcess").ajaxSubmit(options); }




请选择发布的流程:
onclick="doploy()" />


@POST
@Path("/deploy/")
@Produces(MediaType.APPLICATION_JSON)
@LogAnnotation(operationName = "发布流程")
public String deployProcess(@RequestParam(required=false) MultipartFile processDef) {

ZipInputStream zis = null;
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
try {
request.setCharacterEncoding("UTF-8");
String deployFile = request.getParameter("processDef");
if (deployFile != null && !deployFile.isEmpty()) {
ProcessEngine processEngine = Configuration.getProcessEngine();
RepositoryService repositoryService = processEngine
.getRepositoryService();

            zis = new ZipInputStream(processDef.getInputStream());
            repositoryService.createDeployment()
                    .addResourcesFromZipInputStream(zis).deploy();
            zis.close();
        } else {
            return GlobalConstant.FAILURE;
        }
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return GlobalConstant.FAILURE;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return GlobalConstant.FAILURE;
    } finally {
        try {
            if(zis != null){
                zis.close();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
    }
    return GlobalConstant.SUCCESS;
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • baidu_26611019
    蚂蚁冲锋队 2017-08-07 09:50
    已采纳

    var options = {

    target: '#output', //把服务器返回的内容放入id为output的元素中

    beforeSubmit: showRequest, //提交前的回调函数

    success: showResponse, //提交后的回调函数

    url: url, //默认是form的action, 如果申明,则会覆盖

    type: type, //默认是form的method(get or post),如果申明,则会覆盖

    dataType: null, //html(默认), xml, script, json...接受服务端返回的类型

    clearForm: true, //成功提交后,清除所有表单元素的值

    resetForm: true, //成功提交后,重置所有表单元素的值

    timeout: 3000 //限制请求的时间,当请求大于3秒后,跳出请求

    }

    你的程序报的是:不支持的媒体类型,所以定位到dataType字段的属性,你把它换成上面的格式试一下,看看哪一种可以通过

    点赞 评论
  • mky136
    mky136 2017-08-08 01:38

    好像没有作用还是报的415错,看情况是不是form表单的enctype="multipart/form-data"这个属性导致的

    点赞 评论
  • mky136
    mky136 2017-08-08 01:51

    Remote Address:[::1]:8080
    Request URL:http://localhost:8080.........
    Request Method:POST
    Status Code:415 Unsupported Media Type
    Response Headers
    view source
    Content-Language:en
    Content-Length:1135
    Content-Type:text/html;charset=utf-8
    Date:Tue, 08 Aug 2017 01:47:11 GMT
    Server:Apache-Coyote/1.1
    Request Headers
    view source
    Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Accept-Encoding:gzip, deflate
    Accept-Language:zh-CN,zh;q=0.8
    Cache-Control:max-age=0
    Connection:keep-alive
    Content-Length:104583
    Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryo8cij5pOyhpHkBbd
    Host:localhost:8080
    Origin:http://localhost:8080
    Referer:http://localhost:8080/......./test.html
    Upgrade-Insecure-Requests:1
    User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
    Request Payload
    ------WebKitFormBoundaryo8cij5pOyhpHkBbd
    Content-Disposition: form-data; name="processDef"; filename="System.Management.zip"
    Content-Type: application/octet-stream

    ------WebKitFormBoundaryo8cij5pOyhpHkBbd--

    点赞 评论

相关推荐