HTTP status 404-no result defined for Action employeeaction and result input-action class

Source: Internet
Author: User

Add the blue part of the returned type as input to the corresponding location of Struts. XML as prompted. In fact, this solution is not a permanent cure.

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"    "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>    <constant name="struts.enable.DynamicMethodInvocation" value="false" />    <constant name="struts.devMode" value="true" />    <package name="main" extends="struts-default">        <action name="employee_list" method="list"         class="EmployeeAction">            <result>/jsp/employee.jsp</result>            <result name="input">/jsp/employee.jsp</result>        </action>        <action name="employee_create" method="create"         class="EmployeeAction">            <result name="success" type="redirectAction">employee_list</result>            <result name="input">/jsp/employee.jsp</result>        </action>    </package></struts>

The corresponding method of employeeaction is as follows:

public String list(){employees=EmployeeManager.getEmployees();return SUCCESS;}

In struts. XML, only one type is returned. If success is not added to the blue part, an error in the title is displayed. After adding it, it will be fine. In terms of program robustness, struts2 does not require success to add results. As the struts2 interceptor looks like a 404 problem after processing, it is not simply a problem that the path cannot be found, we should not simply add <result name = "input">/some. JSP </result>. The key is to figure out what the Interception Mechanism of struts2 has done. The root cause of the error in the title is that the type conversion fails when struts2 processes data.

The specific explanation is as follows:

The parameters interceptor is responsible for the request parameter ing to the action attribute in struts2. It is a member of the default defaultstack interceptor stack. All request parameters are of the string type, but not all Action attributes are of the string type. Therefore, each non-string action attribute needs to be converted to the corresponding request parameters. Parameters interceptor uses ognl AP to achieve this goal. To be accurate, it is the ognl. ognlruntime class, which depends on Java
Reflection. For each attribute to be set, ognlruntime creates a java. Lang. reflection. Method object for it and calls its invoke method.

Of course, the type conversion is not always successful, because the user input data may not be converted to the corresponding action attribute.

Key points:If the type conversion fails, what solution does struts2 provide for us?

When an error occurs due to type conversion failure, struts does not have to stop. It has two options. The specific choice depends on whether your action class implements COM. opensymphony. xwork2.validationaware interface.

If an action class does not implement the validationaware interface, Struts will continue to call its Action Method in case of a type conversion error, as if nothing had happened.

If an action class implements the validationaware interface, Struts will not call its Action Method in case of a type conversion error: struts will check whether the declaration of the relevant action element contains an input result. If yes, Struts will forward the control to the result element. If such a result cannot be found, Struts will throw an exception. This is why exceptions such as the question are sometimes thrown.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.