gpt4 book ai didi

java - URL 模式不适用于 localhost url(没有 maven 的 jersey)

转载 作者:太空宇宙 更新时间:2023-11-04 13:57:11 26 4
gpt4 key购买 nike

这是我的 web.xml。我已将 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>

我的网页在此图像中,我们可以看到它只是使用 localhost urland 调用 Rest,但它收到了 404 异常。

enter image description here

身份验证.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

关于java - URL 模式不适用于 localhost url(没有 maven 的 jersey),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29702548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com