简体   繁体   中英

Basic web application but getting 404 error Tomcat/Eclipse

I have a simple dynamic web application in eclipse as shown in below image:

在此处输入图片说明

and my web.xml is as below (provided only relavent sections to reduce complexity):

<web-app ... 
<display-name>DemoRest</display-name>
<servlet>
   <servlet-name>JerseyWebService</servlet-name>
   <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>JerseyWebService</servlet-name>
  <url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
  <welcome-file>index.html</welcome-file>
</welcome-file-list>

But when I run I am getting "404 error" as shown below: 在此处输入图片说明

As you can see my Context-Path matches with my folder and actual files are there in correct location, still I am not able to run the application. I tried of cleaning, rebuilding, restarting of eclipse but still no luck. Can anyone help me, why this happens with tomcat?

<servlet-mapping>
   <servlet-name>JerseyWebService</servlet-name>
   <url-pattern>/*</url-pattern>
</servlet-mapping>

This is not available because the url

 http://localhost:8080/DemoRest/NewFile.jsp

will be intercepted by JerseyWebService, which I guess is not an intended action.

Why not host rest services on path like:

<servlet-mapping>
   <servlet-name>JerseyWebService</servlet-name>
   <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM