javax.servlet.ServletException: java.lang.NoSuchMethodException: Action[/common/DepartmentAction] 不包含指定的方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13025131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:13:03  来源:igfitidea点击:

javax.servlet.ServletException: java.lang.NoSuchMethodException: Action[/common/DepartmentAction] does not contain specified method

javastruts

提问by Java Questions

i am getting above exception but i have the action class and method in that Actionclass which i call.

我遇到了异常,但我在我调用的那个 Actionclass 中有动作类和方法。

this is the struts-config.xml.

这是 struts-config.xml。

<action path="/common/DepartmentAction"  name="SecurEyesForm" type="com.secureyes.eswastha.struts.action.DepartmentAction" scope="request" parameter="method" validate="false">
   <forward name="departmentHome" path="/WEB-INF/Masters/DepartmentMaster.jsp"></forward>            
</action>

and this is what is my Action class :

这就是我的 Action 类:

public class DepartmentAction extends DispatchAction {    
    /* forward name="success" path="" */
    private String forwardRequestTo = "success";
    public ActionForward goToHome(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        //call method to verify Pagetoken
        forwardRequestTo = "departmentHome";
        return mapping.findForward(forwardRequestTo);
    }
}

and this is how i call the method in javascript :

这就是我在 javascript 中调用该方法的方式:

function dataSave(){                    
    document.forms[0].action="DepartmentAction.htm";
    document.forms[0].method.value="saveDepartmentDetails";
    document.forms[0].target="workFrame";
    document.forms[0].submit();   
}

when i see the stack trace i see something like this :

当我看到堆栈跟踪时,我看到的是这样的:

SEVERE: Action[/common/DepartmentAction] does not contain method named ''

By which should i to conclude that the method parameter is '' but i have given parameter as method.

StackTrace :

堆栈跟踪 :

Oct 23, 2012 12:29:50 PM org.apache.struts.actions.DispatchAction dispatchMethod
SEVERE: Action[/common/DepartmentAction] does not contain method named ''
java.lang.NoSuchMethodException: com.secureyes.eswastha.struts.action.DepartmentAction.(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    at java.lang.Class.getMethod(Class.java:1622)
    at org.apache.struts.actions.DispatchAction.getMethod(DispatchAction.java:348)
    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:252)
    at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

Oct 23, 2012 12:29:50 PM org.apache.struts.util.PropertyMessageResources loadLocale
WARNING:   Resource org/apache/struts/action/ActionResources_en_US.properties Not Found.
Oct 23, 2012 12:29:50 PM org.apache.struts.util.PropertyMessageResources loadLocale
WARNING:   Resource org/apache/struts/action/ActionResources_en.properties Not Found.
Oct 23, 2012 12:29:50 PM org.apache.struts.action.RequestProcessor processException
WARNING: Unhandled Exception thrown: class java.lang.NoSuchMethodException

Is this version problem of struts framework, because of dispatch action in 1.29 and the version configured with my project is 1.3.9?. if it is version problem how to configure struts 1.2.9 to Netbeans7.2 IDE?`

请问这个是struts框架的版本问题,是1.29的dispatch action,我的项目配置的版本是1.3.9吗?如果是版本问题如何将struts 1.2.9配置为Netbeans7.2 IDE?`

UPDATE :

更新 :

Home page which has all the frames

包含所有框架的主页

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="favicon.ico">
<title>SecureEyes - Infusing Security</title>
<script language="javascript" type="text/javascript" src="<%=resourcePath%>/scripts/frameset.js"></script>
<script language="javascript" type="text/javascript" src="<%=resourcePath%>/scripts/commonForHomePageTemplate.js"></script>
<script language="javascript">
<!--
var opt_no_frames = false;
var opt_integrated_mode = false;
var _help_prefix = "";
var _help_module = "";
var _context = "";
//-->
</script>
</head>
            <frameset border="0" frameborder="0" framespacing="0" rows="64,*">
                    <frame border="0" frameborder="0" framespacing="0" id="topFrame" name="topFrame" src="<%=resourcePath%>/common/header.jsp" marginheight="0" marginwidth="0" noresize="noresize" scrolling="no">
                    <frameset border="0" frameborder="0" framespacing="0" id="MainFrameSet" cols="209,*">
                            <frame noresize="noresize" border="0" frameborder="0" framespacing="0" id="leftFrame" name="leftFrame" src="<%=resourcePath%>/common/left_menu.jsp" >
                            <frame border="0" frameborder="0" framespacing="0" id="workFrame" name="workFrame" src="<%=resourcePath%>/common/WelcomePage.jsp" marginheight="7" marginwidth="7" noresize="noresize" scrolling="auto">
                    </frameset>
            </frameset>
</html>

and DepartemtMaster.jsp

DepartemtMaster.jsp

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> <%@ page contentType="text/html"%> <%@ page pageEncoding="UTF-8"%> <% String resourcePath = request.getContextPath(); %> SecureEyes - Infusing Security

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> <%@ page contentType="text/html"%> <%@ page pageEncoding="UTF-8"% > <% String resourcePath = request.getContextPath(); %> SecureEyes - 注入安全性

    <link rel="stylesheet" type="text/css" href="<%=resourcePath %>/css/autocomplete.css"/>
/scripts/prototype/prototype.js"> /scripts/script.aculo.us/effects.js"> /scripts/script.aculo.us/controls.js"> /scripts/autocomplete.js">
    <script src="<%=resourcePath%>/scripts/blanket.js"></script>


    <script src="<%=resourcePath%>/data-page/jquery-latest.js" type="text/javascript"></script>
    <script type="text/javascript" src="<%=resourcePath%>/data-page/jquery.tablesorter.js"></script>
    <link href="<%=resourcePath%>/data-page/table-sorter.css" rel="stylesheet" type="text/css">
    <link href="<%=resourcePath%>/css/eswastha.css" rel="stylesheet" type="text/css">
    <script src="<%=resourcePath%>/data-page/smartpaginator.js" type="text/javascript"></script>
    <link href="<%=resourcePath%>/data-page/smartpaginator.css" rel="stylesheet" type="text/css" />

    <script language="javascript" type="text/javascript" src="<%=resourcePath%>/scripts/commonForHomePageTemplate.js"></script>
    <script language="javascript" type="text/javascript" src="<%=resourcePath%>/data-page/main.js"></script>
    <script language="javascript" type="text/javascript" src="<%=resourcePath%>/header_data/tooltip.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=resourcePath%>/header_data/general.css">
    <link rel="stylesheet" type="text/css" href="<%=resourcePath%>/data-page/custom.css">
    <link rel="stylesheet" type="text/css" href="<%=resourcePath%>/data-page/layout.css">
    <link rel="stylesheet" type="text/css" href="<%=resourcePath%>/data-page/desktop.css">
    <script src="<%=resourcePath%>/data-page/custom.js"></script>
    <link rel="stylesheet" type="text/nonsense" href="<%=resourcePath%>/header_data/misc.css">

    <script src="../dwr/interface/DepartmentAction.js"></script>
    <script src="../dwr/engine.js"></script>
    <script src="../dwr/util.js"></script>
    <script type="text/javascript">

        function updateList(autocompleter, textBoxValue) {
            document.getElementById("INST_ID_LOADER").style.display = 'none';
            if(textBoxValue!=null && textBoxValue!="" && textBoxValue.length>0){
                document.getElementById("INST_ID_LOADER").style.display = '';
                DepartmentAction.getAutocompleteDepartMentData(textBoxValue,function(data) {
                    document.getElementById("INST_ID_LOADER").style.display = 'none';
                    autocompleter.setChoices(data)
                });
            }
        }
        function nameValueSelector(tag){
            return tag;
        }
        function isDepartmentExist(){
            var departmentName= document.getElementById('department').value;
            DepartmentAction.isDepartmentExist(departmentName,isDepartmentTrue);
        }
        function isDepartmentTrue(isDepartmentExist){
            if(isDepartmentExist){
                 document.getElementById('department').value="";
                 alert("Department exist already");
                return false;
            }
        }

        function getDepartmentData(){
            var departmentName= document.getElementById('departmentName').value;
            DepartmentAction.getDepartmentResultHTML(departmentName,loadDepartmentHTML);
        }
        function loadDepartmentHTML(htmlTable){
            if(htmlTable){
                document.getElementById("departmentList").style.display = "";
                document.getElementById("departmentList").innerHTML = htmlTable;
                document.getElementById("total").value="20";
                //for paginator
                t=40;
                r=0;
                $(function () {
                    r = document.getElementById('rec_per_page').value;
                    $('#paginator').smartpaginator({ totalrecords: t, recordsperpage: 10, datacontainer: 'product-table', dataelement: 'tr', initval: 0, next: 'Next', prev: 'Prev', first: 'First', last: 'Last'});
                });
                prepareForSearch();

            }
        }
        function prepareForSearch(){
            $(function() {      
                $("#product-table").tablesorter();
            }); 

        }
        function deleteDepartment(departmentid){
            if(confirm("Are you sure to delete")){
                alert("departmentid : D :"+departmentid);
            }

        }
        function updateDepartment(departmentid){
            if(confirm("Are you sure to Update")){
                alert("departmentid : U :"+departmentid);
            }
        }
        function addDepartment(){
            document.getElementById("addDepartment").style.display = '';
        }
        function cancelAddDepartment(departmentid){
            document.getElementById("addDepartment").style.display = 'none';
        }
        function saveDepartment(){ 
            var department= document.getElementById('department').value;
            if(department.length<=0){
                alert("Please Enter Department Name");
                return false;
            }else {
                var answer = confirm("Do You Want to Continue?");
                if (answer){
                    dataSave();
                }
            }
        }
        function dataSave(){
            getBlanket('continueDIV');
            document.forms[0].action="DepartmentAction.htm?method=saveDepartmentDetails";
            document.forms[0].method.value="saveDepartmentDetails";
            document.forms[0].target="workFrame";
            document.forms[0].submit();   
        }


    </script>
</head>
<body >
    <div id="blanket" style="display:none;"></div>
    <div id="continueDIV" style="display:none;" align="center" class="loadingRequest">
        <img src="<%=resourcePath%>/images/loading_1.gif" align="middle" border="0"><br /><bean:message key="reqinprogress" />
    </div>
    <form method="get" autocomplete="off">
        <table style="display: none;" id="loaderContainer" onclick="return false;" border="0" cellpadding="0" cellspacing="0" width="100%">
            <tbody><tr><td id="loaderContainerWH"><div id="loader" style="z-index: 10;"><table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td><p><img alt="1x1.gif" title="" id="loaderAnimation" style="background-image: url(/skins/vista/images/loading.gif);" src="left_data/1x1.gif" height="20" width="20"><strong>Please wait. Loading...</strong></p></td></tr></tbody></table></div><script language="JavaScript" type="text/javascript">_lanim_start(24, 20);</script></td></tr></tbody></table>
        <table id="pageLayout" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td id="screenWH">
                        <div class="titleWrapper">
                            <div class="pathbar clear">
                                <span class="pathbarItem"><a href="#">Home</a></span>
                                <span class="pathbarItem separator">&gt;</span>
                            </div>
                            <div class="screenTitle">
                                <table cellspacing="0" width="100%">
                                    <tbody><tr>
                                            <td class="title">
                                                <div class="titleContainer clear"><h1>Master: Department</h1></div>
                                            </td>
                                        </tr>
                                    </tbody></table>
                            </div>  
                        </div>
                        <div id="addDepartment" style="display: none">
                            <table id="commonBodyTable" border="0" cellspacing="0" cellpadding="0" align="center">
                                <tr>
                                    <td>
                                        <table width="100%" align="center" class="tableBorder2" border="0" cellpadding="2" cellspacing="0">
                                            <tr>
                                                <td colspan="4" class="mainheader">Add Department</td>
                                            </tr>
                                            <tr class="lightrow">
                                                <td width="30%" class="textalign">&nbsp;</td>
                                                <td width="5%" class="mandatory">&nbsp;</td>
                                                <td width="65%" colspan="2" class="textfieldalign" >&nbsp;</td>
                                            </tr>
                                            <tr class="darkrow">
                                                <td width="30%" class="textalign">Department Name</td>
                                                <td width="5%" class="mandatory">*</td>
                                                <td width="65%" colspan="2" class="textfieldalign" ><input type="text" class="textbox" name="department" id="department" maxlength="20"  onblur="isDepartmentExist()"></td>
                                            </tr>
                                            <tr class="lightrow">
                                                <td width="30%" class="textalign">&nbsp;</td>
                                                <td width="5%" class="mandatory">&nbsp;</td>
                                                <td width="65%" colspan="2" class="textfieldalign" ><input type="button" class="submitbu" name="save" id="save" value="Save" onclick="saveDepartment()">
                                                    <input type="button" class="submitbu" name="exit" id="exit" value="Exit" onclick="cancelAddDepartment();"></td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="screenBody" id="">
                            <div class="listArea">
                                <div class="searchArea">
                                    <table cellspacing="0" cellspacing="0">
                                        <tbody>
                                            <tr>
                                                <td>
                                                    <label>Department Name</label>
                                                    <input type="text" name="departmentName" id="departmentName" size="50" maxlength="245"  onfocus="new Autocompleter.DWR('departmnet','departmentNameList',updateList,{ valueSelector: nameValueSelector });">
                                                    <img id="INST_ID_LOADER" style="display:none;" src="<%=resourcePath%>/images/loading_3.gif" align="middle" border="0">
                                                    <div id="departmentNameList" class="auto_complete"></div>
                                                </td>
                                                <td>
                                                    <div class="commonButton" id="bid-search">
                                                        <input type="button" name="bname_search" class="submitbu" value="Search" onclick="getDepartmentData()">
                                                    </div>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <form method="post" autocomplete="off" id="mainform">
                                    <div class="report-heading" >
                                        <div align="right">
                                            <a href='#' onclick="addDepartment()">Add Department</a>
                                            <label>Export to:</label>
                                            <select>
                                                <option value="">Excel</option>
                                                <option value="">CSV</option>
                                                <option value="">PDF</option>
                                            </select>
                                            <input type="button" class="submitbu" value="Export" />
                                            <input type="hidden" id="method" name="method" />
                                        </div>
                                    </div>
                                    <div class="gridArea">
                                        <div id="departmentList"></div>
                                    </div>
                                    <input type="hidden" name="total" id="total" value="40" />
                                    <input type="hidden" name="rec_per_page" id="rec_per_page" value="10" />
                                </form>
                                <div id="paginator"></div><!-- for paginator -->
                            </div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
        <div class="LeftFrameSwitcher" id="divLeftFrameSwitcher">
            <img alt="bar_close.gif" title="Hide/show the navigation pane" id="imgLeftFrameSwitcher" onclick="SwitchLeftFrame();" src="<%=resourcePath%>/data-page/bar_close.gif" height="60" width="8">
        </div>
        <input type="hidden" name="method" >
    </form>
</body>

Please help me,

请帮我,

回答by zaffargachal

Please get rid of nested forms and please insert:

请去掉嵌套的表单,然后插入:

<input type="hidden" id="method" name="method">

on first form, this hidden field is missing

在第一个表单中,缺少此隐藏字段

It will help

我会帮你的

回答by Buhake Sindi

A Struts DispatchActionrequires a parameterattribute (as you provided in your struts-config.xml) that matchesyour DispatchActionmethod that you have declared in your action. Bear in mind that the parameter name is case-sensitive and the value passed to the method name is also case-sensitive.

StrutsDispatchAction需要一个您在操作中声明的方法相匹配parameter属性(如您在 中提供的struts-config.xml)。请记住,参数名称区分大小写,传递给方法名称的值也区分大小写。DispatchAction

You have correctly named your DispatchActionby providing a parameter. In order to call your DispatchAction, you have to specify which method in your action to call. This is usually done by appending method=xxxxin your URL as an attribute.

您已DispatchAction通过提供parameter. 为了调用您的DispatchAction,您必须指定要调用的操作中的哪个方法。这通常是通过method=xxxx在您的 URL 中附加一个属性来完成的。

In your case, this is what I might have done:

在你的情况下,这就是我可能做的:

function dataSave(){                    
    document.forms[0].action="DepartmentAction.htm?method=saveDepartmentDetails";
    document.forms[0].method.value="saveDepartmentDetails";
    document.forms[0].target="workFrame";
    document.forms[0].submit();   
}

As you can see, I appended your actionwith the methodparameter key and the name of the method.

如您所见,我为您附加actionmethod参数键和方法名称。

Struts is clearly telling you that it didn't find either an attribute methodor the methodattribute contains no value:

Struts 清楚地告诉您它没有找到属性methodmethod属性不包含任何值:

Action[/common/DepartmentAction] does not contain method named ''

Action[/common/DepartmentAction] 不包含名为 '' 的方法

Hope this helps.

希望这可以帮助。