2012-03-19 39 views
1

我试图对第一个动作的成功运行另一个动作,但是我得到的是错误,表示请求的资源不可用。从struts.xml文件中检查下面的代码。运行动作成功执行动作

<action name="login" class="org.shobhan.action.LoginAction" > 
<result name="success" type="dispatcher">/showProfile</result> 
<result name="error" type="redirect">/Login.jsp</result> 
</action> 
<action name="showProfile" class="org.shobhan.action.ShowProfileAction" > 
<result name="success">/profile.jsp</result> 
</action> 

我有两个java文件LoginAction和ShowProfileAction存在于同一个文件夹中。

回答

0

不要你的成功的呼叫有一个文件扩展名?

+0

像/showProfile.jsp – 2012-03-19 19:02:38

+0

我试过.action,没有工作。 – NotesArt 2012-03-19 19:07:49

1
<result name="success" type="dispatcher">/WEB-INF/showProfile.jsp</result>  
<result name="error" type="dispatcher">/WEB-INF/Login.jsp</result> 

上面没有调用另一个动作,但如果你有在WEB-INF的JSP页面会工作。

分派器解析为一个jsp(以及在这种情况下)和重定向开始从头呼叫。 /Login.jsp是否可以从url中调用?换句话说是CONTEXT_ROOT/Login.jsp可访问吗?如果是这样,那么你可以转发它,如果没有,那么这是不可能的。

一般来说它是不是一个错误后重定向,因为它会删除字段错误(以及任何其他变量和信息,这可能是有用的)一个好主意。

如果你想调用的操作请参见:Action redirect in struts.xml有关调用动作和一些建议更多的选择。

PS:调度员是默认类型,成功是默认的名称,以便您可以简单地写......

<result>/WEB-INF/showProfile.jsp</result>  
<result name="error">/WEB-INF/Login.jsp</result>