3

What is the difference between the 2 URL's :

http://localhost:8084/D_Nappster/NewServlet/

and

http://localhost:8084/D_Nappster/NewServlet

The first URL gets me a 404 response,while the second one works as expected.

From web.xml :

<servlet-mapping>
    <servlet-name>NewServlet</servlet-name>
    <url-pattern>/NewServlet</url-pattern>
</servlet-mapping>
saplingPro
  • 20,769
  • 53
  • 137
  • 195
  • Because there is no URL mapping for NewServlet/ in your web.xml. Your server dosent know where to redirect where a request that ends with NewServlet/ is received. – Jayamohan Jan 27 '13 at 07:27
  • you might want to take a look at http://googlewebmastercentral.blogspot.in/2010/04/to-slash-or-not-to-slash.html – Prateek Jan 27 '13 at 07:37

3 Answers3

2

In general, the first url will be treated as a directory, while the second will be treated as a file.

In your case you have no mapping for the first url so it's being treated as a directory which does not exist, causing a 404.

CIGuy
  • 5,076
  • 28
  • 37
0

Generally a / at the end makes the server assume that it is a Folder and not a servlet mentioned in url-pattern.

http://localhost:8084/D_Nappster/NewServlet/

Therefore, in above case, it tries to find the default page for NewServlet Folder. Whereas, in second url, the server rightly concludes that it is a Servlet and renders UI perfelctly.

Also, you web.xml does not contain a definition for NewServlet/ url-pattern and hence the 404 error.

mihirj
  • 1,199
  • 9
  • 15
0

The first URL without the / goes and accesses the NewServlet class..

The second URL with the / tries to find a folder called NewServlet and access the default setting within the folder

Raghavan
  • 637
  • 3
  • 12