Eclipse 新建 jsp页面里自动生成以下代码:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"😕/"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
作用相当生成了以下路径:
path=WebName ; (当前站点名称)
basePath= http 😕/ localhost : 8080 /WebName /
(http://localhost:8080/WebName/ 这个在IE地址览里最熟悉不过的地址就是这样产生的)
1.这样的好处在于可以为当前的链接使用绝对路径(同时,也强烈推荐使用绝对路径),如:
2.在jsp页面还自动生成了以下代码:
它指定了当前页面的默认地址为basePath,所以
即真实的跳转路径为:http://localhost:8080/WebName/index.jsp
给出一个例子:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"😕/"+request.getServerName()+":"+request.getServerPort()+path+"/";
String result = (String)request.getAttribute("isFail");
if (result!=null)
{
%>
<%
}
%>
浙公网安备 33010602011771号