路径问题--笔记

MyEclipse自动生成的jsp文件中加了下面语句
<base href="<%=basePath%>">

重点问题在basePath,设置了这个之后,这个页面所有的链接都会自动加上你的项目根目录

因此,用相对路径请求、链接都会出问题,注释掉这句就正常了

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%-- <base href="<%=basePath%>"> --%> <!-- 重点问题在basePath,设置了这个之后 这个页面所有的链接都会自动加上你的项目根目录的-->

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<a href="user/UserServlet?action=list">显示用户</a>
</body>
</html>

posted @ 2016-03-22 10:34  hello1world  阅读(108)  评论(0编辑  收藏  举报