路径问题--笔记

mac2022-06-30  59

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>

转载于:https://www.cnblogs.com/Qnana/p/5305149.html

最新回复(0)