Url 模式不适用于本地主机 url(没有 maven 的球衣)
Url pattern doesnot works with localhost url(jersey without maven)
这是我的 web.xml.I 将 url 模式作为 rest.iam 使用 jersey.but 构建网络服务,而 运行 在 tomcat 6.I 出现 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>
我的网页
在此图像中,我们可以看到它只是调用 rest withlocalhost url 并且出现 404 异常。
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....
通过在我的程序中添加以下代码解决了这个问题
return Response.status(201).entity(result).build();
并重新检查此处指定的已安装 jar
Jersey REST Web Service, Tomcat, Eclipse and 404's
这是我的 web.xml.I 将 url 模式作为 rest.iam 使用 jersey.but 构建网络服务,而 运行 在 tomcat 6.I 出现 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>
我的网页 在此图像中,我们可以看到它只是调用 rest withlocalhost url 并且出现 404 异常。
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....
通过在我的程序中添加以下代码解决了这个问题
return Response.status(201).entity(result).build();
并重新检查此处指定的已安装 jar
Jersey REST Web Service, Tomcat, Eclipse and 404's