在没有 ContextPath 的情况下部署 Struts2 应用程序
我在本地 tomcat 上的上下文路径/path"下运行了一个 struts2 应用程序,没有问题.当我将它部署在网络服务器上时(使用代理从http://www.domain.com" 到 "myserver:8080/path/") Struts 做了各种奇怪的事情.
I've got a struts2 application running under a contextpath "/path" on my local tomcat without problems. When I deploy it on a webserver (using a proxy to redirect from "http://www.domain.com" to "myserver:8080/path/") Struts does all kinds of strange things.
首先,它在 -tags 中包含上下文.这可以通过属性关闭.但遗憾的是,它还包括我表单的操作属性中的路径,因此登录表单指向http://www.domain.com/path/login.action" 而不是 "http://www.domain.com/login.action" ...
First, it includes the context in -tags. That can be turned off by an attribute. But sadly, it also includes the path in the action attributes of my forms, so a login form points to "http://www.domain.com/path/login.action" instead of "http://www.domain.com/login.action" ...
是否有可能以某种方式更改此处添加的默认上下文或为表单关闭此功能?(我想保留 -tags,唯一的方法似乎是使用默认的 HTML 表单.)提前致谢!
Is there a possibility so somehow change the default context that is added here or turn this off for forms? (I'd like to keep the -tags, only way round seems to be to use default HTML forms.) Thanks in advance!
我发现其他人也有这个问题,但是框架制作者似乎并不认为这是一个问题.我的解决方案:
I found that others also had the problem, but the framework makers don't seem to think that this is an issue. My solutions:
- 在所有 s:url-tags 中使用 includeContext="false"
- 不要使用 s:form 标签,而是使用通常的表单,将操作设置为actionname.action",并为每个字段包含一个带有 tablerows() 的简单表格.您仍然可以使用 s:textfield 等.
- 遗憾的是,HTTP 会话将不再工作,因为它们被设置为路径/path"(ApplicationPath).这是因为保存 JSESSIONID 的 cookie 被设置为/path.这意味着您的访问者只会在访问 http://www 时获得存储的会话变量.domain.com/path/login.action 并且当它们被重定向回 http://www.domain.com/interestingstuff.action ...我的解决方案是一个 hack,需要通过 JavaScript 设置 JSESSIONID cookie 客户端,如下所述:Struts2:会话问题(反向代理后)
- use includeContext="false" in all s:url-tags
- instead of the s:form tag, use a usual form, set the action to "actionname.action" and include a simple table with tablerows () for each field. You still can use s:textfield and such.
- sadly HTTP sessions won't work anymore as they get set for the path "/path" (the ApplicationPath). This is due to the cookie that saves the JSESSIONID being set to /path. This means that your visitors will only get session variables stored when they're at http://www.domain.com/path/login.action and that those will be lost when they get redirected back to http://www.domain.com/interestingstuff.action ... my solution is a hack that requires setting the JSESSIONID cookie clientside via JavaScript as described here: Struts2: Session Problem (after reverse proxy)
希望这对某人有所帮助...如果您找到更好的解决方案,请告诉我.:-)
Hope this helps someone ... if you find nicer solutions, please let me know. :-)