Struts 2 中的重定向
我在我的 Web 应用程序中使用 Struts 2。
通常,我的应用程序中的 struts 过滤器会在 URL 模式中查找 *.do。
现在还有一个额外的要求;当应用程序输入 时
http://appname:port/login.jsp
,是否显示 login.jsp 的决定取决于业务规则。
因此,理想情况下我应该过滤此 URL 模式并通过 struts 操作(我们将其称为 LoginDecideAction)发送它。
步骤 1 是将 URL 模式添加到 web.xml 中的过滤器 URL 模式中。现在我该如何说 struts 这个 URL 模式 '*login.jsp' 映射到 LoginDecideAction ?
我是 Struts 2 的新手。感谢您的帮助。
I am using Struts 2 in my web application.
Normally, the struts filter in my application looks for *.do in URL patterns.
Now there is an additional requirement; when the application types in
http://appname:port/login.jsp
, the decision to whether or not display the login.jsp is based on business rules.
So I should Ideally filter this URL pattern and send it through a struts action (let's call it LoginDecideAction).
Step 1 is to add the URL pattern in the filter URL pattern in the web.xml. Now how do I say struts that this URL pattern '*login.jsp' maps to LoginDecideAction ?
I am new to Struts 2 . A help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几种方法可以解决这个问题;我将首先对詹姆斯的回答进行一些扩展。
(虽然 S2.0 现在已经很老了;这里是当前操作标签文档)。
公开
login.jsp
文件(即,不要将其放在WEB-INF
下)并使用
标记在其中运行LoginDecideAction
。操作内部的逻辑决定接下来会发生什么,尽管使用executeResult="true"
技术意味着无论发生什么都将出现在login.jsp
URL 中,除非它具有 JavaScript设置窗口位置。在我看来,这有点笨重(而且我不太喜欢
action
标签)。我宁愿 JSP 页面立即重定向到一个操作,该操作要么呈现 JSP 页面,要么呈现不同的 JSP 页面(如果业务逻辑认为应该呈现)。您可以按照您所说的操作,并通过使用
将
属性(请参阅默认值jsp
设置为扩展来让 S2 实际处理.jsp
请求struts.action.extensionstruts.properties
文件文档了解详细信息,但是您需要为其创建一个操作,并且可能确保没有其他.jsp
请求。由S2等处理。可能不值得。There are a couple of ways to go about this; I'll expand a bit on James' answer first.
(Although S2.0 is pretty old now; here's the current action tag docs).
Expose a
login.jsp
file (i.e., don't put it underWEB-INF
) and use the<s:action>
tag inside it to run theLoginDecideAction
. Logic inside the action determines what happens next, although by using theexecuteResult="true"
technique means that whatever happens will be in thelogin.jsp
URL, unless it has JavaScript to set the window location.IMO this is a little clunky (and I'm not a big fan of the
action
tag). I'd rather the JSP page did an immediate redirect to an action that either rendered the JSP page, or rendered a different JSP page if the business logic says it should.You could conceivably do what you're saying and have S2 actually process the
.jsp
request by settingjsp
as an extension using thestruts.action.extension
property (see the defaultstruts.properties
file docs for details. But then you'd need to create an action for it, and probably make sure that no other.jsp
requests were handled by S2, etc. Probably not worth it.如果您可以显示您的login.jsp,请添加
s:action
标记来调用可以处理您的业务逻辑的Struts 操作。要显示视图,请使用executeResult="true"
。有关 s:action 的更多信息,请参阅以下链接:http://struts .apache.org/2.0.14/docs/action.html
If you can get your login.jsp displayed, add
s:action
tag to call the Struts action which can take care of your business logic. To display the view, useexecuteResult="true"
. For more information on s:action, refer to the link below:http://struts.apache.org/2.0.14/docs/action.html