<!-- 该页面为index.jsp -->
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath(); //表示: path=/项目名 假设此时的项目名为Test
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
// 表示: http 127.0.0.1 8080 /Test
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <!-- 相当于:<base href=http://127.0.0.1:8080/Test> -->
<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="aaa.html">这是一个超链接</a>
<!-- 由于有base标签:则表示为:<a href="http://127.0.0.1:8080/Test/aaa.html">这是一个超链接</a> -->
<!-- 如果没有base标签:则就是相对路径了,即aaa.html与index.jsp位于同一目录下面 -->
</body>
</html>
本文详细介绍了JSP页面的基本配置方法,包括设置页面语言、导入Java包、定义字符集等。通过实例展示了如何使用<%@ %>指令来设置页面属性,并解释了如何利用<base>标签实现链接的绝对路径配置。
2599

被折叠的 条评论
为什么被折叠?



