简体   繁体   中英

Put to webservice doesn't work using Form in Java

My code looks like that:

        Form form = new Form();
        form.param("svnr", svnr);
        form.param("vorname", vorname);
        form.param("nachname", nachname);
        client.target(REST_SERVICE_URL + "/lehrer").request(MediaType.APPLICATION_JSON)
                .put(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class);

And the webservice looks like that:

@PUT
@Path("/lehrer")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response createLehrer(@FormParam("svnr") String svnr, @FormParam("vorname") String vorname,
        @FormParam("nachname") String nachname, @Context HttpServletResponse servletResponse) {
    Lehrer lehrer = new Lehrer(svnr, vorname, nachname);

    ManagementDAO.instance.addLehrer(lehrer);


    return Response.ok(lehrer, MediaType.APPLICATION_JSON).build();
}

I get this exception:

javax.servlet.ServletException: javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:968)
org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:795)
org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:91)
org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:683)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:228)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:679)
org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:435)
org.glassfish.jersey.client.JerseyInvocation$Builder.put(JerseyInvocation.java:323)
klauss.examples.jsf.db.JSFDatabase.addLehrer(JSFDatabase.java:167)

Do you know how to fix that problem? I have no idea how to fix it. I have tried everything but nothing seems to work.

The 500 Internal Server Error is a very general HTTP status code that means something has gone wrong on the website's server, but the server could not be more specific on what the exact problem is.

You are getting HTTP code 500 means, your client is reaching to server.You need to add some loggers in your server side code. Probably a try{}catch() block to find what's wrong on the server side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM