01_4_Struts路径问题

01_4_Struts路径问题

1. Struts路径问题说明

struts2中的路径问题是根据action的路径而不是jsp路径来确定,所有尽量不要使用相对路径。

虽然可以使用redirect方式解决,但redirect方式并非必要。

解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextRoot方式拿到webapp的路径)或者使用myeclipse经常用的,指定basePath

2. jsp配置绝对路径

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<head>

 <base href="<%=basePath%>">

</head>

原文地址:https://www.cnblogs.com/flyback/p/8644818.html