How load servlet on index.jsp
Just change the welcome file URL to be the one of the servlet.
Given this servlet mapping,
<servlet-mapping>
<servlet-name>indexServlet</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
just have this welcome file list:
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
Don't forget to move the /index.jsp
into /WEB-INF
folder to prevent it from being accessed directly by endusers guessing its URL (and don't forget to alter the forward call in the index servlet to point to /WEB-INF/index.jsp
).
Or if you solely intend to have a "home page servlet" and not an "index servlet", then map the servlet to the empty string URL pattern instead of as welcome file.
<servlet-mapping>
<servlet-name>indexServlet</servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
See also:
- How to call a servlet on jsp page load?
- Difference between / and /* in servlet mapping url pattern