我在提出休息请求时遇到404错误。我的环境详情如下:
泽西岛1.91.1
Apache Tomcat / 7.0.42
Java jdk1.7.0_80
我的 web.xml 看起来像这样
<web-app>
<display-name>Archetype Created Web Application</display-name>
<listener>
<listener-class>com.company.gcs.zanshin.notificationengine.web.ContextStarter</listener-class>
</listener>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.company.gcs.zanshin.notificationengine.web</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/operations/*</url-pattern>
</servlet-mapping>
当我启动tomcat时,我看到jersey正在加载正确加载的所有资源类
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
May 20, 2016 5:33:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Executables\tomcats\NotificationEngine\webapps\notification
May 20, 2016 5:33:03 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Executables\tomcats\NotificationEngine\webapps\notification\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
May 20, 2016 5:33:09 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [312] milliseconds.
May 20, 2016 5:33:09 PM com.sun.jersey.api.core.servlet.WebAppResourceConfig init
INFO: Scanning for root resource and provider classes in the Web app resource paths:
/WEB-INF/lib
/WEB-INF/classes
May 20, 2016 5:33:12 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class com.company.gcs.zanshin.notificationengine.web.ExcelRestPoints
class com.company.gcs.zanshin.notificationengine.web.FileRestPoints
class com.company.gcs.zanshin.notificationengine.web.NotificationRestPoints
class com.company.gcs.zanshin.notificationengine.web.WordRestPoints
class com.company.gcs.zanshin.notificationengine.web.EmailRestPoints
May 20, 2016 5:33:12 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
May 20, 2016 5:33:12 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:42 PM'
May 20, 2016 5:33:13 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
May 20, 2016 5:33:13 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
May 20, 2016 5:33:13 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9893 ms
HTTP请求
POST http://localhost:8080/notification/operations/file/upload HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 144
Accept: application/json, text/plain, */*
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryYeOKGTo9xFMhvjUB
Referer: http://localhost:8080/notification/ui/index.html
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,ur;q=0.6,hi;q=0.4,ar;q=0.2
HTTP响应
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Length: 0
Date: Fri, 20 May 2016 12:25:50 GMT
Java程序
@Path("/operations")
class FileRestPoints {
@Path("/file/upload")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public def upload(
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail,
@FormDataParam("notificationId") String notificationId)
{
FileUploader uploader = new FileUploader();
String fileName = fileDetail.getFileName();
def resp = uploader.upload(notificationId,fileName,uploadedInputStream)
return toJson(resp);
}
}
答案 0 :(得分:0)
我通过在localhost:8080 / notification / operations / operations / file / upload等网址中提供两次操作来解决这个问题。这是因为在web.xml和Java类中都有关键字 operations 。