In the Java Web is often found in the 404 Web page error, the reason is generally the wrong path to access.
The path in the Java Web is divided into two cases by my method, of course, the use of relative path is consistent, this article only say absolute path.
Suppose there is a login.html,index.jsp under the MyApp project, and two Servleta and Servletb are written.
Address configuration in Web. xml:
<url-pattern>/servlet/servletA</url-pattern>
<url-pattern>/servlet/servletB</url-pattern>
In case one: if the/start in the path, then this/equivalent http://localhost:8080/
1, login.html has a form form submitted to Servleta, then the action to fill the path:
Absolute path mode: action= "/myapp/servlet/servleta"------Http://localhost:8080/myapp/servlet/servletA
Relative path mode: action= "Servlet/servleta"------Http://localhost:8080/myapp/servlet/servletA
2, login.html has a <a> link to index.jsp so
Absolute path mode: href= "/myapp/index.jsp"------http://localhost:8080/myapp/index.jsp
Relative path mode: action= "index.jsp"------http://localhost:8080/myapp/index.jsp
3. Redirect to Servleta in index.jsp
Absolute path mode: Sendredirect ("/myapp/servlet/servleta"); ------Http://localhost:8080/myapp/servlet/servletA
Relative path mode: Sendredirect ("Servlet/servleta"); ---Http://localhost:8080/myapp/servlet/servletA
In case two: if the/start in the path, then this/equivalent http://localhost:8080/myapp/
1.servletA forwarding to Servletb
Absolute path mode: Request.getrequestdispatcher ("/servlet/servletb"). Forward (request, response);
--------Http://localhost:8080/myapp/servlet/servletB
Relative path mode: Request.getrequestdispatcher ("Servlet/servletb"). Forward (request, response);
--------Http://localhost:8080/myapp/servlet/servletB
String P=this.getservletcontext (). Getrealpath ("/"); -----G:\environment\tomcat\webapps\myapp\
Path problems in the Java Web.