Url模式不适用于localhost url(没有maven的jersey)

时间:2015-04-17 14:50:41

标签: java web.xml url-pattern

这是我的web.xml.I hasputted url模式为rest.iam使用jersey构建web服务。但是在tomcat中运行时6.我收到404错误。

Web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<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">
<servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>
                     com.sun.jersey.spi.container.servlet.ServletContainer
                </servlet-class>

     <init-param>

      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.snapshothealthapp1.controller</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

我的网页 在这张图片中我们可以看到它只是callig rest withlocalhost urland它正在获得404异常。

enter image description here

Authentication.java

import com.snapshothealthapp1.database.Dbclass;
    import com.snapshothealthapp1.model.AuthenticationModel;
    import com.snapshothealthapp1.model.Jsonparser;
    @Path("/customers")
    public class Authentication {
        @GET
        @Path("/get")
    //  @Produces("json")
        public Response getRequestUrl(@PathParam("get") String msg) {
            //TODO:Create a JSON(recieved from client request)
    //      JSONObject jsonClient = new JSONObject(); 
            System.out.println("inside Authentication");




        String JSON_DATA =
         "{" 
           + "  \"SnapshotRequest\": [" 
           + "    {" 
           + "      \"AuthenticationType\": \"email\"," 
           + "      \"EmailAddress\": \"test@gmail.com\","                  
           + "      \"Password\" : \"12345\"," 
           + "      \"PracticeID\" : \"null\"," 
           + "      \"DeviceID\" : \"null\""
           + "    } +   ]"
       + "}";


        //TODO : ADD JSON PARSER 
        List arr = new ArrayList();
        Jsonparser jp=new Jsonparser();
        arr =jp.jsonParser(JSON_DATA);

    //      
    //      
    //      
    //      
    //      String result=null;
    //  return Response.status(201).entity(result).build();
    return null;
        }


        @POST
        @Produces("text/html")
        public Request getUnamePswd(){
            AuthenticationModel auth=new AuthenticationModel();

            String Uname="Username@gmail.com";
            String Password="Password";
            String AuthTypeID="12345678";
    //      String Uname="username or practice_Id";


                try {
                    auth.validateUser(Uname,Password,AuthTypeID);
                } catch (NullPointerException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }




            return null;




        }


 Can anybody helpme?Any help will be highly appreciable....

1 个答案:

答案 0 :(得分:0)

通过在我的程序中添加以下代码解决了这个问题

return Response.status(201).entity(result).build();

并重新检查此处指定的已安装的罐子

Jersey REST Web Service, Tomcat, Eclipse and 404's