How you can write code in Servlet for throwing the httpd error 404?
How to add the configuration for handling the not found error in the web.xml file?
Thanks
Hi,
Add the following code in the web.xml file:
<error-page> <error-code>404</error-code> <location>/WEB-INF/views/notfound.jsp</location> </error-page>
and in the servlet you can use the following code:
public void doGet(HttpServletRequest request, HttpServletResponse response) { response.sendError(HttpServletResponse.SC_NOT_FOUND); }
Check more Servlet tutorials.
Thanks
Ads