How to invoke the servlets correctly if .html files are placed inside a folder within Web Content?

I am able to invoke the servlets correctly if I place the .html files under Web-Content and fail to invoke the servlets if I place them after creating a new folder within Web-Content?

Package Explorer Tree Structure

The one selected(in blue) when run is able to invoke the specified servlet. But for the 2 files placed under folder javaTpoint, after running these files, Error 404 renders. If I move to the location where the selected one is, then the case works fine.

I have to create the folders so as to better streamline the file in web applcn.

Upvotes: 0

Views: 1191

Answers (1)

Previously, when the .html files were placed within the WebContent, and not within a folder inside WebContent, the mappings corresponding to the servlet in web.xml was as mentioned below:

<servlet>
    <servlet-name>sendRedirect1</servlet-name>
    <servlet-class>org.javatpoint.MySearcherOnSendRedirect</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>sendRedirect1</servlet-name>
    <url-pattern>/searchOnSendRedirect</url-pattern>
</servlet-mapping>

where the /searchOnSendRedirect within

<url-pattern>/searchOnSendRedirect</url-pattern>

is pointing to the servlet invoked when pressing the submit button in a form element in a .html file

<form action="searchOnSendRedirect"> 

Now, whenever we create a folder within WebContent and place some .html files, the url-pattern needs to be changed as reflected below:

<url-pattern>/javaTpoint/searchOnSendRedirect</url-pattern>

where javaTpoint is the name of the folder created within WebContent.

Upvotes: 1

Related Questions