Struts2/Struts1动作调用 [英] Struts2 / Struts1 action calls

查看:98
本文介绍了Struts2/Struts1动作调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Struts2和Struts1的应用程序上工作.现在,我想对不同的操作实施身份验证.我想使用interceptor来检查namespaceaction属于哪个.我用Struts2动作包装了所有Struts1动作.因此,所有的strut1动作都通过拦截器进行.

<action name="contactsList" class="com.opensymphony.xwork2.ActionSupport">
    <result name="success">contactsList.do</result>
</action>

问题在于,如果用户在浏览器中输入struts1动作,拦截器将不会被调用.

我的问题:来自浏览器的动作调用与通过Struts配置调用的动作调用之间是否有区别?如果可能,是否有可能从浏览器中禁止Struts1动作,但允许在struts中允许它?

解决方案

您认为方向错误. Struts2中有一个 Struts1插件,它实际上包装了Struts1动作.因此,代码看起来像

<action name="contactsList" class="org.apache.struts2.s1.Struts1Action">
  <param name="className">com.mycompany.myapp.ContactsListAction</param>
  <result>contactsList.jsp</result>
</action>

对于您的问题,Struts2返回的结果将重定向或分派到servlet,即使您的操作什么也不做.您可以使用浏览器执行任何操作,但是Struts会接受请求,直到将其映射到负责对浏览器请求做出响应的url为止.

i work on an application that uses Struts2 and Struts1. Now i want to implement authentication for different actions. I'd like to use an interceptor to check to which namespace an action belongs. I wrapped all Struts1 action with Struts2 action. So all strut1-action run through the interceptor.

<action name="contactsList" class="com.opensymphony.xwork2.ActionSupport">
    <result name="success">contactsList.do</result>
</action>

The problem is that if a user enters a struts1-action in the browser the interceptor will not be called.

My question: Is there a difference between action calls coming from the browser and action calls called via Struts configuration. If it is possible, is it possible to disallow Struts1 actions from the browser but from within struts it is allowed?

解决方案

You have thought in the wrong direction. There's a Struts1 plugin in Struts2 that actually wraps the Struts1 action. So, the code will look like

<action name="contactsList" class="org.apache.struts2.s1.Struts1Action">
  <param name="className">com.mycompany.myapp.ContactsListAction</param>
  <result>contactsList.jsp</result>
</action>

To your question the Struts2 return result that either redirect or dispatch to the servlet even if your action doing nothing. You could do anything with the browser but Struts will accept requests until you map it to the url where it's responsible to react on the browser requests.

这篇关于Struts2/Struts1动作调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆