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

xiaoxiao2021-03-06  43

<% @ page contenttype = "text / html; charset = GBK"%>

<% @ Page Import = "java.io. *"%>

<%

/ / The relative path to the current file in Servlet and JSP and the absolute path

// jsp

Out.println ("" The absolute path corresponding to the root catalog: " Request.getRequesturi () " ");

String strpathfile = Application.getRealPath (Request.getRequesturi ());

OUT.PRINTLN ("" The absolute path of the file: " StrPathFile " ");

Out.println (Application.getRealPath));

String strdirPath = new file (Application.getRealpath (Request.getRequesturi ()))). GetParent ();

Out.println ("The absolute path of the directory:" STRDIRPATH "");

%>

// servlet

The Application object in // JSP is ServerContext in the servlet, so this is so good in servlet.

// Import java.io.file;

System.out.Println ("The absolute path corresponding to the root catalog:" Request.getServletPath () "");

String strpathfile = request.getSession (). GetServletContext (). GetRealPath ());

System.out.println ("The absolute path of the file:" StrPathFile ");

String strdirpath = new file (). GetServletContext (). GetRealPath ())). GetParent ();

System.out.println ("The absolute path of the directory:" STRDIRPATH "");

The file name cannot include the following characters: //: *? "<> |

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

New Post(0)