简体   繁体   English

在Java中使用Form不能放入Web服务

[英]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: Web服务看起来像这样:

@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. 500 Internal Server Error是一个非常普通的HTTP状态代码,表示网站的服务器出了点问题,但是服务器不能更确切地说明确切的问题是什么。

You are getting HTTP code 500 means, your client is reaching to server.You need to add some loggers in your server side code. 您将获得HTTP代码500,这意味着您的客户端已连接到服务器。您需要在服务器端代码中添加一些记录器。 Probably a try{}catch() block to find what's wrong on the server side. 可能使用try {} catch()块来查找服务器端的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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