JSP application.getContextPath()方法:返回当前Web应用的路径

  • 内容
  • 评论
  • 相关

该方法返回当前 Web 应用的路径,路径以“/”开头。

语法:

getContextPath()

返回值:

  • 返回当前 Web 应用的路径。

示例

将当前 Web 应用的路径显示在页面中,关键代码如下:

<%
  String path=application.getContextPath();
  out.print(path);
%>

如在名称为“02”的项目的 index.jsp 页面中输出当前Web应用的路径,运行结果为:
在页面中显示当前 web 应用的路径:/02

本文标题:JSP application.getContextPath()方法:返回当前Web应用的路径

本文地址:https://www.hosteonscn.com/6204.html

评论

0条评论

发表评论

邮箱地址不会被公开。 必填项已用*标注