<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!--1. 得到主机名和应用名的全路径 -->
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--2.在head里面设置路径后,当前页面所有连接前面都使用basePath所指定的路径-->
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>Insert title here</title>
</head>
<body>
struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径。
[url=index.jsp]index.jsp[/url]
虽然可以用redirect方式解决,但redirect方式并非必要。
解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextPath方式来拿到webapp的路径)
或者使用myeclipse经常用的,指定basePath
</body>
</html>
struts2的path路径问题
最新推荐文章于 2021-03-20 02:31:22 发布