错误泽西岛客户-MULTIPART_FORM_DATA

时间:2018-09-30 01:28:50

标签: java jersey jersey-client

我在Formulatios method =“ post” enctype =“ multipart / form-data”时遇到问题。

我的表单具有以下代码:

<form id="frmForm" name ="frmForm" action="admin?action=register" method = "post" enctype = "multipart/form-data">
    
  </form>

我的servlet具有以下类:

protected void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter ("action");
System.out.println (action);
    try {
        switch (action) {
            case "apanel":
                apanel (request, response);
                break;
            case "register":
                System.out.println ("intro");
                register (request, response);
                break;
            default:
                break;
        }
    } catch (SQLException e) {
    e.getStackTrace ();
    }


}

private void register(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
// TODO Auto-generated method stub
String dincio = request.getParameter ("dincio");
String dfin = request.getParameter ("dfin");
String idgroup = request.getParameter ("idgroup");
String screen = request.getParameter ("screen");
String file1 = request.getParameter ("file1");
String name = request.getParameter ("name");
String file2 = request.getParameter ("file2");


try {

ClientConfig cc = new DefaultClientConfig ();
cc.getClasses (). add (MultiPartWriter.class);
Client theClient = Client.create (cc);

final WebResource theWebResource = theClient.resource ("http://localhost:8086/WS/apics/Upload");

final FormDataMultiPart part = new FormDataMultiPart ();

part.field ("dincio", dincio);
part.field ("dfin", dfin);
part.field ("idgroup", idgroup);
part.field ("screen", screen);
part.field ("file1", file1);  //image 1
part.field ("name", name);
part.field ("file2", file2);  //image 2


ClientResponse restResponse = theWebResource.type (MediaType.MULTIPART_FORM_DATA) .post (ClientResponse.class, part);


if (restResponse.getStatus ()! = 200) {
throw new RuntimeException ("Failed: HTTP error code:" + restResponse.getStatus ());
}
else {
String statusString = restResponse.getEntity (String.class);
               
            if (! statusString.contentEquals ("false"))
                {
                response.sendRedirect ("admin?action=show");
                }
            else
                {
                response.sendRedirect ("/view/sw/new.jsp");
                }          
}
}
catch (Exception e)
{
System.out.println ("exception" + e.getMessage ());
}

}

当我离开以下形式的表单quitanto enctype =“ multipart / form-data”时,我会收到参数并将记录保存在Webservice中,但是图像不会保存。

<form id = "frmForm" name = "frmForm" action ="admin?action=register" method = "post">
    
  </ form>

当我使用enctype加密=“ multipart / form-data”离开表单时,我没有收到参数,并且在tomcat 8中出现以下错误:

    Estado HTTP 500 – Internal Server Error
Tipo Informe de Excepción

mensaje La ejecución del Servlet lanzó una excepción

descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.

excepción

javax.servlet.ServletException: La ejecución del Servlet lanzó una excepción
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
causa raíz

java.lang.AbstractMethodError: javax.ws.rs.core.Response.getStatusInfo()Ljavax/ws/rs/core/Response$StatusType;
    javax.ws.rs.WebApplicationException.computeExceptionMessage(WebApplicationException.java:205)
    javax.ws.rs.WebApplicationException.<init>(WebApplicationException.java:179)
    javax.ws.rs.WebApplicationException.<init>(WebApplicationException.java:244)
    javax.ws.rs.WebApplicationException.<init>(WebApplicationException.java:155)
    com.sun.jersey.multipart.impl.MultiPartWriter.writeTo(MultiPartWriter.java:194)
    com.sun.jersey.multipart.impl.MultiPartWriter.writeTo(MultiPartWriter.java:71)
    com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300)
    com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204)
    com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
    com.sun.jersey.api.client.Client.handle(Client.java:648)
    com.sun.jersey.api.client.WebResource.handle(WebResource.java:670)
    com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:563)
    com.coinsales.sw.rest.servlets.CoinsalesServlet.registrar(CoinsalesServlet.java:196)
    com.coinsales.sw.rest.servlets.CoinsalesServlet.doGet(CoinsalesServlet.java:68)
    com.coinsales.sw.rest.servlets.CoinsalesServlet.doPost(CoinsalesServlet.java:99)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
nota La traza completa de la causa de este error se encuentra en los archivos de diario del servidor.

请您的支持以帮助我解决此错误。

0 个答案:

没有答案