Struts2 java. Lang. nosuchmethodexception Exception Handling

Source: Internet
Author: User

This error occurred not long ago when I was studying struts. I searched the internet for a long time and found that the answer was different. It is summarized as follows for your reference.

1,

Have you tried other methods? If this is the case, it may be that your action class does not inherit dispatchaction or other classes in structs. Also, pay attention to the parameter list of the method. The type order must be correct, in the following order: actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response

2,

Two errors may cause the preceding exceptions:

1. The action class method is defined as the private type.

The method accessed in the following action is defined as private. When the program accesses its method, the above exception is thrown.

3,

Java. Lang. nosuchmethodexception has two root causes: first, some jar files are missing; second, some jar files are duplicated.

4,

Problems with struts2 framework
When jquery Ajax is used on the page to call the vailduname method in action, an error is returned, indicating that my method does not exist. But it actually exists.
Public String vailduname (string loginname) throws exception {}
The problem is that there is no parameter in struts2 (I don't know why)

Solution:
Private string loginname;
Public String vailduname () throws exception {}
Getter and setter methods of loginname
In this way, you can use ajax to call

· Struts2 uses the reflection mechanism to execute action. Currently, the struts2 standard does not require parameters for action methods. There are two different methods: parameter methods and parameter-free methods, therefore, it may not be found.

5,

The jar version is incorrect.

It should be a problem with the 3.6jar package. It's okay to switch back to the 3.2 package.

6,

Java. Lang. nosuchmethodexception this exception means that you do not have this method in your action. It indicates that you have found the action but have not found the method. Therefore, there are two situations,

In the third case, the action you submitted is not the same. Check the configuration file to see if there is the same path.

In 2nd cases, your action does not have this method.

 

 

 

Below is the reprinted

 

public class NoSuchMethodException
Extends exception

This exception is thrown when a specific method cannot be found.

Bytes ------------------------------------------------------------------------------------------------------------------------

Actually, I have a specific method. Why does struts2 report this exception?

The following is a segment of the struts2 configuration file:

<Package name = "basedate" extends = "struts-Default" namespace = "/basedate">
<! -- Service provider management -->
<Action name = "saveorupdatebranch" class = "branchaction" method = "saveorupdatebranch">
<Result name = "success">/WEB-INF/pages/srvclink/basedate/branch. jsp </result>
<Result name = "input">/WEB-INF/pages/srvclink/basedate/branch. jsp </result>
</Action>
<Action name = "editbranch" class = "branchaction" method = "editbranch">
<Result name = "success">/WEB-INF/pages/srvclink/basedate/branch. jsp </result>
</Action>
<Action name = "deletebranch" class = "branchaction" method = "deletebranch">
<Result name = "success" type = "Redirect"> saveorupdatebranch. Action? Isnew = true </result>
</Action>
<Action name = "searchbranch" class = "branchaction" method = "searchbranch">
<Result name = "success">/WEB-INF/pages/srvclink/basedate/branch. jsp </result>
</Action>

<! -- Carrier Management -->
<Action name = "saveorupdatebranch" class = "carrieraction" method = "saveorupdatebranch">
<Result name = "success">/WEB-INF/pages/srvclink/basedate/carrier. jsp </result>
</Action>
<Action name = "editcarrier" class = "carrieraction" method = "editcarrier">
<Result name = "success">/WEB-INF/pages/srvclink/basedate/carrier. jsp </result>
</Action>
<Action name = "deletecarrier" class = "carrieraction" method = "deletecarrier">
<Result name = "success" type = "Redirect"> saveorupdatecarrier. Action? Isnew = true </result>
</Action>
<Action name = "searchcarrier" class = "carrieraction" method = "searchcarrier">
<Result name = "success">/WEB-INF/pages/srvclink/basedate/carrier. jsp </result>
</Action>
</Package>

Careful friends should be able to find out, because copy and paste make the trouble. As a result, two action definitions with the same name exist in the same namespace. This is not the key. The key issue is that instance references for two actions with the same name are different, and struts2 is the action configured for sequential resolution, if we request saveorupdatebranch, struts2 will query whether the requested action exists in the namespace/basedate. If so, this action is called, if no exception is reported, the user is notified that the specified action cannot be found in the requested namespace ". Here, the requested action exists. If it is wrong, it is sequential parsing. Even if your first action is correctly defined, it is not called. It will continue to search for the action under/basedate. When it finds that there is another action named saveorupdatebranch and the last aciton, it will call the requested action. However, the reference of the last executed action does not exist.
The instance of this action with the same name is class = "carrieraction ". In fact, the instance carrieraction does not have the "saveorupdatebranch" method, so struts2 throws an exception that cannot find a specific method.

Carelessly killing people...

 

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.