简体   繁体   English

Struts2:struts.xml不转发到动作名称

[英]Struts2: struts.xml doesn't forward to action name

You will suppose this is a big question.but there might be a simple problem which I can't find the reason. 你会认为这是一个很大的问题。但是可能有一个简单的问题,我找不到原因。

There is a form( a simple login) whose action name is 'loginAction' in a jsp page called 'index.jsp' . 在一个名为'index.jsp'的jsp页面中有一个表单(一个简单的登录名),其动作名称是'loginAction'。 In the action class, the execute() method checks whether the username,password are valid. 在action类中, execute()方法检查用户名,密码是否有效。 If it is a valid login, execute() method returns SUCCESS which forward to another jsp page called 'account.jsp' in a folder called 'jsp' inside WEB-INF. 如果它是有效的登录,则execute()方法返回SUCCESS,该SUCCESS转发到WEB-INF内名为'jsp'的文件夹中名为'account.jsp'的另一个jsp页面。

The problem is that, struts.xml forwards all valid logins to the relavant url , but the page(account.jsp) cannot be retrieved.Browser gives 404 error.But the url which the browser says 'not available' was just copied and pasted to the browser's address bar manually. 问题是,struts.xml将所有有效登录转发给relavant url,但是无法检索页面(account.jsp)。浏览器给出了404错误。但是浏览器显示“不可用”的网址只是被复制并粘贴了手动到浏览器的地址栏。 Then the page is displayed !!! 然后页面显示!!!
Here is the struts.xml file 这是struts.xml文件

<struts>

<include file="/struts_auth.xml" />
<package name="default" extends="struts-default" >

    <action name="login" >
        <result>index.jsp</result>
    </action>        
    <action name="loginAction" class="com.app.action.LoginAction">
        <result name="success">/auth/acc</result>    
        <result name="input">index.jsp</result>
    </action>

</package>

Here is the struts_auth.xml file which is included in above struts.xml 这是struts_auth.xml文件,它包含在上面的struts.xml中

<struts>

<package name="author" extends="default" namespace="/auth" >

    <action name="acc">
        <result name="success">/WEB-INF/jsp/account.jsp</result>  
        <result name="input">index.jsp</result>
    </action>   

</package>

and this is what browser says as the reason 这就是浏览器所说的原因
description: The requested resource (/app/auth/acc) is not available. But if this url (http://localhost:8084/app/auth/acc)just copied into the browser's address bar, it just shows the real page . 但是如果这个url(http:// localhost:8084 / app / auth / acc)刚刚复制到浏览器的地址栏中,它只显示真实页面。 Please let me know where my problem is. 请告诉我我的问题所在。

For better understanding refer the following link. 为了更好地理解,请参阅以下链接。 How to redirect to another action 如何重定向到另一个操作

  <!-- Redirect to another namespace -->
    <result name="success" type="redirectAction">
        <param name="actionName">acc</param>
        <param name="namespace">/auth</param>
    </result>

problem lies here: <result name="success">/auth/acc</result>. 问题在于: <result name="success">/auth/acc</result>. If there is no type name given in the node,then struts2 itself will set dispatcher as the default type.You can modify your code like this: <result name="success" type="redirectAction"> <param name="actionName">actionName</param> <param name="namespace">namespace</param> ` 如果节点中没有给出类型名称,那么struts2本身会将调度程序设置为默认类型。您可以像这样修改代码: <result name="success" type="redirectAction"> <param name="actionName">actionName</param> <param name="namespace">namespace</param> `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM