(一)struts2中的路径要使用绝对路径,不能使用相对路径
可以在jsp中配置,在head标签中指定<base href="<%=basePath%>">,在写路径时,在body标签中使用链接<a>就不用在href中添加<%=basePath%>
<a href="<%=basePath%>index.jsp">路径问题</a>
<%@ 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%>"/>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<h2>hello world!</h2>
<a href="person/Person_say">小明</a>
</body>
</html>
(二)第二种方法:可以在head标签内直接添加基目录:<base href="项目全路径" />
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="http://localhost:8080/项目名/" />
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<h2>hello world!</h2>
<a href="person/Person_say">小明</a>
</body>
</html>