在我的应用程序中,我使用了 struts2,并创建了一个基本操作来解决路径问题:
class BaseAction{
private String path;
static{
HttpServletRequest request = ServletActionContext.getRequest(); path=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();+"/";
}
}
然后所有其他动作扩展这个基本动作。
在我的 jsp 页面中,我将路径添加为基础:
xx.jsp:
....
<head>
<base href="<s:property value='path'/>">
<script ... src="res/test.js" />
</head>
它在我自己的机器上运行良好。
http://localhost:8080/app test.js 可以通过“http://localhost:8080/app/res/test.js”找到
但是当其他人尝试访问我的应用程序时,他们使用:
现在,浏览器仍然尝试通过“http://localhost:8080/app/res/test.js”下载test.js
当然,它不能得到它。真实路径应该是: http://192.168.xx:8080/app/res/test.js
既然,“路径”是行动中的硬代码,有什么办法解决这个问题吗?