如何在struts2中隐藏url中的action名称

发布于 2024-10-26 05:15:37 字数 672 浏览 2 评论 0原文

从标题中可以看出,问题是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何以畏孤独 2024-11-02 05:15:37

看起来您正在使用根上下文。因此,可以肯定地说您通常会通过访问 http://www.domain.com/home.action 来访问您的操作吗?

如果是这样,那么您可以在 struts.xml 中将 HomeAction 配置为默认操作。

示例

<action name="home" class="...">
    ...
</action>

<default-action-ref name="home"/>

然后,如果您仅请求 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

<action name="home" class="...">
    ...
</action>

<default-action-ref name="home"/>

Then, if you request just http://www.example.com/, it should invoke your home action.

長街聽風 2024-11-02 05:15:37

已解决

不要写条件,只写这个->

RewriteRule ^/index$  /home.action [L] 

你的index.jsp应该是:

<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-9" />
    <meta name="verify-v1" content="tonewfwefwewfwefwefrz4tqvroPwefewfy3izuwefwefKs=" />  
    <meta http-equiv="refresh" content="0;url=" /> 
</head>
<body>  
  <%
  response.setStatus(301); 
  response.setHeader( "Location", "/" );
  response.setHeader( "Connection", "close" );  
  %>    
</body>

Solved;

Don't write a condition, just only this ->

RewriteRule ^/index$  /home.action [L] 

And your index.jsp should be:

<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-9" />
    <meta name="verify-v1" content="tonewfwefwewfwefwefrz4tqvroPwefewfy3izuwefwefKs=" />  
    <meta http-equiv="refresh" content="0;url=" /> 
</head>
<body>  
  <%
  response.setStatus(301); 
  response.setHeader( "Location", "/" );
  response.setHeader( "Connection", "close" );  
  %>    
</body>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文