The relative path where the current file is located in Servlet and JSP and the absolute path

xiaoxiao2021-03-05  25

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)));

转载请注明原文地址:https://www.9cbs.com/read-32613.html

New Post(0)