About path problems in JavaWeb

In the browser
/The beginning is the relative path indicates the current host address ==>http://localhost:8080, that is, the server directory, not the web application

<a href="/xxx"> <form action = "/ xxx">==>http://localhost:8080/xxxThis is obviously incorrect, we still need to/xxxBefore counted, our project name is like this.http://localhost:8080/project/xxx
Get the way the project name
JSP expression:

<%= request.getContextPath() %>

el expression:

${pageContext.request.contextPath }



In the server
/The beginning is the relative path indicates that the current web application address ishttp://localhost:8080/project

Request.getContextPath () // Get the project root path
Request.getServletPath () // Get servlet path
Request.getRequesturi () // Get the server request path, that is, the full path behind the port number
Request.getRealPath ("/") // Get absolute path for web applications

Supplement: ServletContext objects have taken several ways:

System.getProperty ("user.dir") // Get the current project's work directory