尝试访问tomcat服务器时的HTTP 404状态

时间:2018-03-29 20:38:45

标签: java web-services jersey jax-rs

我正在尝试使用jax-rs,jersey实现Web服务。我使用IntelliJ,tomcat。这是我的web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>jersey sample</display-name>
  <servlet>
    <servlet-name>Jersey</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>org.glassfish.jersey.config.property.packages</param-name>
// Here I am not sure which one is correct, main.java.controller or just
// controller? Controller is the class that I keep my endpoints (for 
// example the below controller) in it.
// (Both does not solve my problem)
      <param-value>main.java.controller</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey</servlet-name>
    <url-pattern>/api/*</url-pattern>
  </servlet-mapping>
</web-app>

控制器:

@Path("/user")
public class UserRegistrationController {

@GET
@Path("/register")
@Consumes(APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public Response getSiteAllCallReport(@Context HttpServletRequest request, MultivaluedMap<String, String> form) throws SQLException, JSONException {
    JSONObject data = UserRegitrationProvider.registerUser(request, form);
    return Response.ok().entity(data.toString()).build();
}
}

当我运行tomcat并在浏览器中输入“localhost:8080 / api / user / register”时,我获得了HTTP 404状态。我在哪里做错了?

0 个答案:

没有答案