The Application object in // // jsp is the serverContext in the servlet, so this is this in the servlet // import java.io.file; system.out.println ("The Absolute Path corresponding to the root directory:" Request.getServletPath () ""); string strpathfile = Request.getSession (). getServletContext (). getRealPath (Request.getRequesturi ()); system.out.println ("File absolute path:" strpathfile "" String strdirPath = new file (Request.getSession (). GetRealPath (Request.getRequesturi ())))))))). GetParent (); system.out.println ("Directory absolute path:" strDirPath "" ); File names cannot include the following characters: //: *? "<> |
Use the above method * Blue * actually returned to a directory name, inexplicable? ? Unbelievable, huh, huh, unknown!
Use the following method in our program, you can open the file string url = getRequest (). GetServletPath (); int it = url.lastindexof ("/"); string servletpath = url.substring (0, it); string realdir = GetRealPath (ServletPath); // RealDir "//" file name BufferedReader Br = New BufferedReader (New FileInputStream (RealDir // " TemplateFileName)));