In a Java Web App, there is an attribute of the web.xml file called the welcome-file-list
.
The welcome-file-list
tells the web app what URLs to pull up if nothing more specific is specified.
Typically, this value is configured for index.jsp
, but it can be any mapping within the web application.
If you wanted to have a servlet respond, instead of index.jsp
, then you would map the servlet properly, and then use that reference in the welcome-file-list
.
Consider:
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>IndexServlet</servlet-name>
<servlet-class>pkg.IndexServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>IndexServlet</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
Here we have the pkg.IndexServlet
mapped to /index
. We also tell the application that index
is the welcome file for this application. So, internally, when the application sees http://host.com/webapp
, it will automatically append index
to it, and then route that appropriately, which will lead it to the servlet mapped to /index
.
Once you have this mapped properly, you want to do a pattern much @Matthias did here, where the servlet gathers the data, and then forwards to the JSP.