gpt4 book ai didi

java - 如何从通过 apache ErrorDocument 重定向到达的 Struts 2 Action 中获取原始 REQUEST_URI?

转载 作者:行者123 更新时间:2023-11-30 01:39:39 24 4
gpt4 key购买 nike

如何从 Struts 2 Action 中访问 REQUEST_URI?在 perl/php/ruby 中,可以通过 ENV["REQUEST_URI"] 等轻松获得。在java中,似乎PageContext.getErrorData().getRequestURI()就是我正在寻找的,但遗憾的是,PageContext似乎没有在操作中定义,要么是因为ErrorDocument重定向使请求看起来不像错误,或者因为它是稍后定义的。

具体示例

给定一个 apache 前端(mod_jk/ajp)struts 2 应用程序在 tomcat 上通过 apache 中的 ErrorDocument 404 配置到达。包含以下详细信息:

-- 原始请求 url(触发 404)--

http://server/totally/bogus/path

-- http.conf --

ErrorDocument 404 /struts2app/lookup.action

--struts Action --

public String bogusUrlLookup() {
HttpServletRequest request = ServletActionContext.getRequest();

// contains /lookup.action as does request.getRequestURI();
String url = RequestUtils.getServletPath(request);

// PageContext is null, so I cannot reach ErrorData from it.
log.info("pageContext="+ServletActionContext.getPageContext());

// Not in the ENV
// Map env = System.getenv();

// Not in the ATTRIBUTES
// request.getAttributeNames()

// Not in HEADER
// request.getHeaderNames()

return ERROR;
}

我需要的只是字符串“/totally/bogus/path”,但在上面的操作中,我能找到的唯一 URL 字符串是“/struts2app/lookup.action”。我与 ErrorDocument 绑定(bind)在一起,因为完全/虚假/路径不太可能位于我的应用程序的命名空间内,因为 apache 提供其他非 tomcat 资源。

最佳答案

request.getAttribute("javax.servlet.forward.request_uri")

关于java - 如何从通过 apache ErrorDocument 重定向到达的 Struts 2 Action 中获取原始 REQUEST_URI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1203951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com