如何在struts2中隐藏url中的action名称
从标题中可以看出,问题是:
RewriteCond %{SERVLET_PATH} ^/(.+)
RewriteRule ^/(.+) /home.action [L]
->那么如果我输入domain.com/blahblah,则 home.action 将被执行
但是如果:
RewriteCond %{SERVLET_PATH} ^/
RewriteRule ^/ /home.action [L]
->然后我输入domain.com -> home.action 永远不会被执行!
我使用了一个index.jsp(并在web.xml中声明)并添加:
response.sendRedirect("home.action");
DIDN'T work
然后添加:
<META HTTP-EQUIV="Refresh" CONTENT="1;URL=home.action">
DIDN'T work
因此,我将很高兴听到您的解决方案,以便仅通过以下方式执行操作键入不带任何路径的域 url。如:domain.com
提前致谢。
As you see from the title, the problem is:
RewriteCond %{SERVLET_PATH} ^/(.+)
RewriteRule ^/(.+) /home.action [L]
-> then if I type domain.com/blahblah the home.action will be executed
However if:
RewriteCond %{SERVLET_PATH} ^/
RewriteRule ^/ /home.action [L]
-> then I type domain.com -> home.action never be executed!
I used an index.jsp (and declare in web.xml as well) and add:
response.sendRedirect("home.action");
DIDN'T work
Then add:
<META HTTP-EQUIV="Refresh" CONTENT="1;URL=home.action">
DIDN'T work
As a result, I would be appreciated to hear your solutions in order to execute an action by only type the domain url without any path. Such as: domain.com
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在使用根上下文。因此,可以肯定地说您通常会通过访问
http://www.domain.com/home.action
来访问您的操作吗?如果是这样,那么您可以在 struts.xml 中将
HomeAction
配置为默认操作。示例
然后,如果您仅请求
http://www.example.com/
,它应该调用您的主操作。It looks like you are using a root context. Therefore, would it be safe to say that you would normally access your action by going to
http://www.domain.com/home.action
?If so, then you can configure
HomeAction
as the default action in your struts.xml.Example
Then, if you request just
http://www.example.com/
, it should invoke your home action.已解决;
不要写条件,只写这个->
你的index.jsp应该是:
Solved;
Don't write a condition, just only this ->
And your index.jsp should be: