我知道这个问题被问了太多次,但是我已经被困3个小时了,并且已经通过阅读很多Stack Overflow帖子尝试了很多方法来解决这个问题而且我做出了决定在这里提交一个问题。
我附加了我的依赖项列表和项目结构以及我用作Web服务的代码的一部分。
项目结构:
依赖关系:
<groupId>survey</groupId>
<artifactId>survey</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!--https://mvnrepository.com/artifact/javax.mail/mail-->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!-- Apache Commons Codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-oauth2</artifactId>
<version>v2-rev120-1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-plus</artifactId>
<version>v1-rev453-1.22.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json used by sign in-->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>LATEST</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-server
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19.1</version>
</dependency>-->
<!--Jersey container servlet-->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.25.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet-core -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25</version>
</dependency>
</dependencies>
的web.xml:
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>survey.rest</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<!--<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>survey.rest.SurveyResourceConfig</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>
包含Jersey
的restful Web服务的类@Path("v1") public class SysAdminRest extends RestService {
@GET
@Path("/{sentBy}/{codeUn}")
@Produces(MediaType.APPLICATION_JSON)
public void redirectToLoginPage(@PathParam("sentBy")int sentBy, @PathParam("codeUn") String code_un){
Customer customer = null;
try {
customer = new SystemManager().getCustomerByCodeUN(code_un);
request.setAttribute(Constants.CUSTOMER_OBJECT, customer);
/*request.getServletContext()
.getRequestDispatcher("survey/servlet/Survey.java").forward(request, response);*/
request.getServletContext()
.getRequestDispatcher("survey/servlet/survey").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
现在,当我将其部署到本地主机并在以下地址进行get调用时:
我得到的错误是:
HTTP状态404原始服务器未找到目标资源的当前表示
我的代码或依赖项有什么问题吗? 等待一些回答,提前谢谢。