您的位置:首页 > 编程语言 > Java开发

Struts2 path 路径问题说明

2017-06-22 22:25 465 查看
index.jsp<%--String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";//在head中<base href>指定basePath--%><!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><meta http-equiv="Content-Type" content="text/html; charset=GB18030" /><title>Insert title here</title></head><body><a href="path/path.action">路径问题说明</a></body></html>path.jspString path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
<base href="<%=basePath%>" /><title>Insert title here</title></head><body>struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径。<br /><a href="index.jsp">index.jsp</a><br />虽然可以用redirect方式解决,但redirect方式并非必要。<br />解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextRoot方式来拿到webapp的路径)<br />或者使用myeclipse经常用的,指定basePath</body></html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: