【发布时间】:2013-05-15 22:23:16
【问题描述】:
我有网址: http://demo.lendingclub.com/account/summary.action。 访问这个url时,会先到authenticate interceptor,在拦截器类中,如果我使用:
String uri = req.getRequestURI();
它将返回/account/summary.action
但是如果我在jsp中使用它:
<%
HttpServletRequest req = ServletActionContext.getRequest();
String uri = req.getRequestURI();
%>
它将返回:/mainapp/pages/account/summary.jsp
为什么它们不同,如何在 JSP 中获取操作 URL?
【问题讨论】:
-
有一个解决方案:
String namespace = ServletActionContext.getActionMapping().getNamespace(); String action = ServletActionContext.getActionMapping().getName(); uri = namespace + "/" + action + ".action";但我觉得太复杂了!! -
<s:url value="/" />- stackoverflow.com/q/15755583/1700321 -
@AleksandrM 不错,但它仍然可以更短;)
-
@Quaternion:是的,如果需要操作 url,那么它应该是
<s:url />。 -
我知道他们为什么不同: