在struts2中使用拦截器捕获根时出现问题
我有一个intercetpor,它检查用户在执行请求的操作之前是否已登录。我已尝试将此设置为所有操作的默认设置。除一个地址外,所有地址都像一个符咒。当我转到我的根URL时在struts2中使用拦截器捕获根时出现问题,struts2,interceptor,login-control,interceptorstack,Struts2,Interceptor,Login Control,Interceptorstack,我有一个intercetpor,它检查用户在执行请求的操作之前是否已登录。我已尝试将此设置为所有操作的默认设置。除一个地址外,所有地址都像一个符咒。当我转到我的根URL时“http://localhost:8080/map/“由于某种原因,拦截器没有开火。我猜struts.xml中缺少了一些东西,但我不知道是什么: <struts> <constant name="struts.devMode" value="true" /> <constant
“http://localhost:8080/map/“
由于某种原因,拦截器没有开火。我猜struts.xml中缺少了一些东西,但我不知道是什么:
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources,DatabaseResources" />
<package name="map" extends="struts-default">
<interceptors>
<interceptor name="loginintercept"
class="se.contribe.intercept.LoginInterceptor" />
<interceptor-stack name="defaultLoginStack">
<interceptor-ref name="loginintercept" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="defaultLoginStack" />
<default-action-ref name="index"></default-action-ref>
<global-results>
<result name="loginneeded">/login.jsp</result>
</global-results>
<action name="index" class="**.map.MapAction">
<result>/index.jsp</result>
</action>
<action name="login">
<result>/login.jsp</result>
</action>
<action name="loginInput" class="**.session.LoginAction">
<result type="redirectAction">
<param name="actionName">index</param>
</result>
<result name="input">/login.jsp</result>
<result name="error">/login.jsp</result>
</action>
<action name="*" class="**.map.MapAction">
<result>/index.jsp</result>
</action>
</package>
</struts>
/login.jsp
/index.jsp
/login.jsp
指数
/login.jsp
/login.jsp
/index.jsp
我把类名弄糊涂了一点,以防万一我的雇主会反对。
您的根url可能是,但包“映射”指的是
您可能需要为根目录所在的“/”定义一个包,您可能需要为“”定义一个包,该包允许在任何包中执行其中的操作。
编辑:在上面我混淆了名称空间的名称(似乎使用了太多约定插件!)
我强烈怀疑,如果您检查web.xml文件,您会发现如下内容:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
index.jsp
如果你把它改成
<welcome-file-list>
<welcome-file>index.action</welcome-file>
</welcome-file-list>
行动指数
您将得到您所期望的,因为我可以同时拥有index.jsp和index.action,并且更改该设置可以选择其中一个。
您的根url可能是,但包“映射”指的是
您可能需要为根目录所在的“/”定义一个包,您可能需要为“”定义一个包,该包允许在任何包中执行其中的操作。
编辑:在上面我混淆了名称空间的名称(似乎使用了太多约定插件!)
我强烈怀疑,如果您检查web.xml文件,您会发现如下内容:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
index.jsp
如果你把它改成
<welcome-file-list>
<welcome-file>index.action</welcome-file>
</welcome-file-list>
行动指数
您将得到您所期望的,因为我可以同时拥有index.jsp和index.action,并且更改该设置可以选择一个或另一个。我最终设法解决了这个问题。
我在的执行阶段测试了向控制台写入一个简单的输出
<action name="index" class="**.map.MapAction">
当我打开网页时,控制台中没有打印任何输出。这让我思考。我的主页名为index.jsp,显然这个名称绕过了Struts的常规控件。将名称更改为index2.jsp解决了此问题。可能还有其他地方我可以改变这种行为,但简单地改变名字更容易 我终于找到了自己的答案。
我在的执行阶段测试了向控制台写入一个简单的输出
<action name="index" class="**.map.MapAction">
当我打开网页时,控制台中没有打印任何输出。这让我思考。我的主页名为index.jsp,显然这个名称绕过了Struts的常规控件。将名称更改为index2.jsp解决了此问题。可能还有其他地方我可以改变这种行为,但简单地改变名字更容易 是调用索引操作的请求吗?如果是这样的话,将为该请求调用哪些拦截器?是否为调用索引操作的请求?如果是这样,将为该请求调用哪些拦截器?@Qyaternion我想您是在谈论包的名称空间。如果未提供名称空间,则使用名称空间“”。包的name属性只是一个名称,除非提供名称空间,否则不存在与url的连接。至少这是我从Apache参考手册中得出的结论。@Qyaternion我想你说的是包的名称空间。如果未提供名称空间,则使用名称空间“”。包的name属性只是一个名称,除非提供名称空间,否则不存在与url的连接。至少这是我从Apache参考手册中得出的结论。