Search code examples
javaspringjspstrutstiles

DispatchAction ServletException: Request does not contain handler parameter named 'method'


I have searched all over and am unable to find an answer to my issue. From what I know about DispatchAction's this code should be working fine. The stack trace is as follows. I am using Struts1.3 and Spring with tiles for layouts (Please excuse my code blocks I am pretty new to using stackoverflow) Please let me know if you need more information to help me. Thanks for your time.

javax.servlet.ServletException: Request[/authorizeShipment] does not contain handler parameter named 'method'.  This may be caused by whitespace in the label text. 
    at org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:197)
    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:245)
    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:731)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:344)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:110)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:98)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:95)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:79)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:55)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:36)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:178)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:188)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:106)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:356)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:150)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3367)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)

Here are my code snippets:

DispatchAction:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.multivision.mmt.action.form.AuthorizeShipmentForm;
import com.multivision.mmt.business.ShipmentBusDelegate;

public class AuthorizeShipmentAction extends DispatchAction {
    public ActionForward authorize(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
        AuthorizeShipmentForm asf = (AuthorizeShipmentForm) form;
        String shipmentId = asf.getShipmentId();
        ShipmentBusDelegate sbd = new ShipmentBusDelegate();
        try{
            sbd.authorizeShipment(shipmentId);
            return mapping.findForward("authorizeSuccess");
        } catch(Exception ex){
            System.out.println("could not approve or decline shipment");
            ex.printStackTrace();
            return mapping.getInputForward();

        }

    }

    public ActionForward deny(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
        AuthorizeShipmentForm asf = (AuthorizeShipmentForm) form;
        String shipmentId = asf.getShipmentId();
        ShipmentBusDelegate sbd = new ShipmentBusDelegate();
        try{
            sbd.denyShipment(shipmentId);
            return mapping.findForward("authorizeDenied");
        } catch(Exception ex){
            System.out.println("could not approve or decline shipment");
            ex.printStackTrace();
            return mapping.getInputForward();

        }

    }
}

Here is my JSP:

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <html:form action="authorizeShipment.do" method="post">
        <table>
            <tr>
                <td>AuthorizeShipment ID</td><td><html:text property="shipmentId"/></td>
            </tr>
            <tr>
             <td><html:submit property="method" value="authorize"></html:submit></td><td><html:submit property="method" value="deny"></td>      
        </tr>

    </table>
    </html:form>
</body>
</html>

My struts-config.xml

<action parameter="method" path ="/authorizeShipment" name="authorizeShipmentForm"input=".authorizeShipment" validate="false" scope="request" >
<forward name="authorizeSuccess" path=".authorizeSuccess" />
    <forward name="authorizeDenied" path=".authorizeFailure" />
</action>

My action-servlet.xml

    <bean name="/authorizeShipment" class="com.multivision.mmt.action.AuthorizeShipmentAction"/>

Solution

  • The exception is raised because Struts cannot find a "method=xxxx" in HTTP request.

    I think you should change from

    <html:submit parameter="method" value="deny">
    

    to

    <html:hidden parameter="method" value="deny"> or some other tags for hidden.
    

    I mean, the "method=deny" should be looked as

    <input type="hidden" name="method" value="deny"/>
    

    In your HTML pages generated from the JSP. Please check that.

    PS : You can use Browser Developer tool to check HTTP requests. All recent browsers can do that.