What's the difference in putting a "slash" at the end to make a URL?

What is the difference between the two urls:

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

      

and

http://localhost:8084/D_Nappster/NewServlet

      

The first url gets the response 404

and the second one works as expected.

From web.xml:

<servlet-mapping>
    <servlet-name>NewServlet</servlet-name>
    <url-pattern>/NewServlet</url-pattern>
</servlet-mapping>

      

+3


source to share


3 answers


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



In your case, you don't have a mapping for the first url, so it is treated as a directory that doesn't exist by calling 404.

+2


source


Usually the a /

at the end makes the server assume it's a folder and not the servlet mentioned in the sample url.

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

      



So in this case, it tries to find the default page for the NewServlet folder. Whereas, in the second url, the server correctly infers that it is servlets and renders the UI fine.

In addition, web.xml does not contain a definition for the NewServlet/

url template and hence 404 errors.

0


source


The first url without / goes and refers to the NewServlet class ..

The second url with / is trying to find a folder named NewServlet and access the default setting in the folder

0


source







All Articles