web path

Relative path 
1.
<! - 2. " / " at the beginning of the relative address -> <! - / represents the entire web project, namely: HTTP: // localhost: 8080 / -> <A the href = " /javaee/jsp/b.jsp "> this is the " / "at the beginning of the relative address of a hyperlink </a>

2.
! <-    
    does not begin with a /, the path relative to the resources of the current   
    path of the current resource is: HTTP: // localhost: 8080 / JavaEE / JSP /  
  and b.jsp Also in this path  so the direct writing b.jsp  - ->  <a href= ""> b.jsp, which is not in " / "relative address at the beginning of a hyperlink </a> 

. 3.
<! - 3 not to / relative address of the beginning ->   
        ! <-    
            not to / relative path with respect to the beginning of the current path to the resource  at this time is the address of form.jsp: HTTP: // localhost: 8080 /javaee/jsp/form.jsp so the current path for the resource: HTTP: // localhost: Servlet path of 8080 / javaee / jsp and to submit to Http: // localhost: 8080 / JavaEE / PathServlet so the path to the current path i.e., a path on the path: ../ PathServlet NOTE: .. represent the current path of current paths on a path -> <Action = form. " ../PathServlet " methoe = " GET "> username: <INPUT type = " text " name = " username " value = ""> <INPUT type = "submit" value=" Form is submitted to the Servlet --- not to / relative address that begins "> </ form>


. 4.

    ServletContext access to resources

  Here ServletContext access to resources of the path is relative to the system of absolute path (in Windows is with a letter, can be used to obtain specific path to upload or download files).

  The basic syntax: servletContext.getRealPath ( "path"); path parameter is a relative path must be "/" at the beginning, you can not use the "/" at the beginning, but whether or not to use "/" at the beginning are relative to the current application path It recommended (so you can try unification) begin with "/."

  Additional methods of obtaining ServletContext follows:
    1) use the request acquisition:. Request.getSession () GetServletContext ();
    2) obtaining in a Servlet: this.getServletContext ();
    . 3) using the object to obtain FilterConfig (used in the Filter): config .getServletContext ();

   ServletContext access to resources must be a relative path, not an absolute path, but whether it is the beginning / or does not begin with a /, the path is relative to the current resource phase.  

 

Guess you like

Origin www.cnblogs.com/jentary/p/11572670.html