Results 1 to 7 of 7

Thread: @controller @requestMapping issues in resolving paths

  1. #1
    Join Date
    Oct 2012
    Posts
    4

    Default @controller @requestMapping issues in resolving paths

    Hello

    First post ever at this site. Hopefully, I posted to the correct forum. My issue is that I am trying to map my @controller class @RequestMapping's to unique methods via params but have not been to successful! Below is my @controller class, snippet of web xml config file and snippet of jsp.
    The end result is an error thrown at the server:
    Any ideas would be appreciated... tried a bunch of different things and either I get a page with nothing on it or an error thrown by the springframework.

    [10/19/12 11:19:16:274 EDT] 0000001e ErrorsTag E org.springframework.web.servlet.tags.RequestContex tAwareTag doStartTag Invalid property 'do?param1=edit' of bean class [com.servlet.ghesiForms.OpenResidentialAccountTenan tCommand]: Bean property 'do?param1=edit' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'do?param1=edit' of bean class [com.servlet.ghesiForms.OpenResidentialAccountTenan tCommand]: Bean property 'do?param1=edit' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?


    XML Snippet
    <servlet-mapping>
    <servlet-name>ghesiforms</servlet-name>
    <url-pattern>/openResidentialAccountTenant.do</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
    <servlet-name>ghesiforms</servlet-name>
    <url-pattern>/openResidentialAccountTenant.do?param1=edit</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
    <servlet-name>ghesiforms</servlet-name>
    <url-pattern>/openResidentialAccountTenant.do?param1=confirmatio n</url-pattern>
    </servlet-mapping>
    _______
    Controller class

    @Controller
    @RequestMapping("/openResidentialAccountTenant")
    public class OpenResidentailAccountTenantController{



    @RequestMapping(method=RequestMethod.GET)
    public String setupForm(ModelMap model){
    System.out.println("in openResidentialAccountTenant GET");
    OpenResidentialAccountTenantCommand openResidentialAccountTenant = new OpenResidentialAccountTenantCommand();
    model.addAttribute("openResidentialAccountTenant", openResidentialAccountTenant);
    return "openResidentialAccountTenant";

    }

    @RequestMapping(method=RequestMethod.POST, params = {"param1=edit"})
    public String onSubmit(@ModelAttribute("openResidentialAccountTe nant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    System.out.println("in openResidentialAccountTenant POST");
    if(result.hasErrors()){
    return "openResidentialAccountTenant";
    }
    return "openResidentialAccountTenant_confirmation";
    }

    @RequestMapping(method=RequestMethod.POST, params = {"param1=confirmation"})
    public String onConfirmationSubmit(@ModelAttribute("openResident ialAccountTenant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    System.out.println("in openResidentialAccountTenant POST");
    if(result.hasErrors()){
    return "alldone_confirmationShouldntHappen";
    }
    return "allDone_confirmation";
    }

    }
    _______________________________

    JSP


    <form:form commandName="openResidentialAccountTenant.do?param 1=edit">
    <div id="OpenResidentialAccountTenantForm" >
    <h3><a href="#">Step 1 - Add Customer Information</a></h3>
    <div id="customerInfo">

    etc....etc...
    <tr>
    <td><br>
    <input type="submit" value="Submit"/></td>
    </tr>
    </table>
    </div>
    </div>
    </form:form>
    Last edited by E=MC2orFb=E; Oct 19th, 2012 at 10:50 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    For starters I would suggest a read on how servlet mappings work and after that a read of the reference guide. For starters your servlet mapping is just wrong... Should be only *.do (judging by your URL's) ..

    Also judging from your stacktrace you are submitting something illegal as, for some reason, the .do is interpreted as a field name ...

    Finally next time use [ code][/code ] tags when posting code/xml/stacktraces that way it remains readable..
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2012
    Posts
    4

    Default

    Hi Marten

    Thanks for the feedback....Yes, I originally had *.do but when things were not working I started to second guess myself! Here's what I had in the original code and configuration file:

    Code:
    @Controller
    @RequestMapping("/openResidentialAccountTenant")
    public class OpenResidentailAccountTenantController{
    
    
    	
    	@RequestMapping(method=RequestMethod.GET)
    	public String setupForm(ModelMap model){
    		System.out.println("in openResidentialAccountTenant GET");
    		OpenResidentialAccountTenantCommand openResidentialAccountTenant = new OpenResidentialAccountTenantCommand();
    		model.addAttribute("openResidentialAccountTenant", openResidentialAccountTenant);
    		return "openResidentialAccountTenant";
    		
    	}
    	@RequestMapping(method=RequestMethod.POST, params = "editit")
    	public String onSubmitNoParams(@ModelAttribute("openResidentialAccountTenant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    		System.out.println("in openResidentialAccountTenant POST");
    		if(result.hasErrors()){
    			System.out.println(result.getAllErrors());
    			return "openResidentialAccountTenant";
    		}
    		return "openResidentialAccountTenant_confirmation";
    	}
    	
    
    
    	@RequestMapping(method=RequestMethod.POST, params = "confirmit")
    	public String onConfirmationSubmit(@ModelAttribute("openResidentialAccountTenant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    		System.out.println("in onConfirmationSubmit POST ");
    		if(result.hasErrors()){
    			return "alldone_confirmationShouldntHappen";
    		}
    		return "allDone_confirmation";
    	}
    
    ____XML___
    
    
    	<servlet-mapping>
    		<servlet-name>ghesiforms</servlet-name>
    		<url-pattern>*.do</url-pattern>
    	</servlet-mapping>
    ________
    JSP's
    First Form JSP Page
    <form:form commandName="openResidentialAccountTenant">
     <div id="OpenResidentialAccountTenantForm" > 	
      	<h3><a href="#">Step 1 - Add Customer Information</a></h3>
      	<div id="customerInfo">
     
    	<table border="0" cellpadding="0">
    
    		<tr>
    			<td><b>Customer Information</b></td>
    		</tr>
    etc......
    		<tr>
    			<td><br>
    			<input type="submit" name = "submit" value = "editit" /></td>
    		</tr>		
        </table>
        </div>  
    </div>
    </form:form>
    
    
    Second JSP
    Confirmation page snippet
       <form:form commandName="openResidentialAccountTenant.do">   
     	<div id="submitInfo">
    	<table border="0" cellpadding="0">
    		<tr>
    			<td><br/>
    			  <input type="submit" value="Everything looks okay, please submit"  name = "confirmit" value = "confirmit" />
    			</td>
    		</tr>		
        </table>
        </div> 
        </form:form>
    I read the documentation but it just doesn't seem to provide a solid example of what I am trying to do....

    ie. First JSP form to enter/edit data.
    Second JSP for final confirmation.
    Onecontroller class to distinguish between two different post methods... controlled by params value of either "editit" or "confirmit"

    When I changed everything back to the above the controller can't seem to find the correct request mapping.

    ie. [10/22/12 8:23:32:327 EDT] 00000050 PageNotFound W org.springframework.web.servlet.mvc.support.Defaul tHandlerExceptionResolver handleHttpRequestMethodNotSupported Request method 'POST' not supported

    I'm fairly new to the Spring model but have used similar frameworks in the past. I'm hoping to leverage Spring/Hibernate and some recently learned jQuery syntax in this project. So far, this is the only piece of the project that is causing hair loss!

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Your mapping is wrong...

    Your servlet is looking for URLs ending in *.do (openResidentialAccountTenant.do) whereas your controller is listening to /openResidentialAccountTenant without .do... So it is never going to match...

    Your form is also wrong your commandName is the name of your form backing object not a URL ... Also there is nothing that sends the parameters so I'm not sure how you are going to decide between which URL if you don't send the parameters.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Oct 2012
    Posts
    4

    Default

    Quote Originally Posted by Marten Deinum View Post
    Your mapping is wrong...

    Your servlet is looking for URLs ending in *.do (openResidentialAccountTenant.do) whereas your controller is listening to /openResidentialAccountTenant without .do... So it is never going to match...

    Your form is also wrong your commandName is the name of your form backing object not a URL ... Also there is nothing that sends the parameters so I'm not sure how you are going to decide between which URL if you don't send the parameters.
    Hi Marten

    When I changed everything to the following it seams that only the non params post method "onSubmitTest" gets executed. How can I narrow the request by making my desired POST method to execute instead of the generic test one I just created.
    I thought that adding a name/value pair on the submit would provide the criteria required to narrow the scope of the request.

    Code:
    	<servlet-mapping>
    		<servlet-name>ghesiforms</servlet-name>
    		<url-pattern>*.do</url-pattern>
    	</servlet-mapping>
    
    ______________________________________________
    
    package com.servlet.ghesiForms;
    
    
    import javax.validation.Valid;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    
    
    
    
    /*
     *  Configure the class as an MVC controller 
     *
     *  Configure the class to process the url "/enquiry"
    */
    
    @Controller
    @RequestMapping("openResidentialAccountTenant.do")
    public class OpenResidentailAccountTenantController{
    
    
    	
    	@RequestMapping(method=RequestMethod.GET)
    	public String setupForm(ModelMap model){
    		System.out.println("in openResidentialAccountTenant GET");
    		OpenResidentialAccountTenantCommand openResidentialAccountTenant = new OpenResidentialAccountTenantCommand();
    		model.addAttribute("openResidentialAccountTenant", openResidentialAccountTenant);
    		return "openResidentialAccountTenant";
    		
    	}
    	
    	@RequestMapping(method=RequestMethod.POST)
    	public String onSubmitTest(@ModelAttribute("openResidentialAccountTenant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    		System.out.println("in openResidentialAccountTenant POST");
    		if(result.hasErrors()){
    			System.out.println(result.getAllErrors());
    			return "openResidentialAccountTenant";
    		}
    		return "openResidentialAccountTenant_confirmation";
    	}
    	
    	@RequestMapping(method=RequestMethod.POST, params = "editit")
    	public String onSubmitNoParams(@ModelAttribute("openResidentialAccountTenant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    		System.out.println("in openResidentialAccountTenant POST");
    		if(result.hasErrors()){
    			System.out.println(result.getAllErrors());
    			return "openResidentialAccountTenant";
    		}
    		return "openResidentialAccountTenant_confirmation";
    	}
    	
    
    
    	@RequestMapping(method=RequestMethod.POST, params = "confirmit")
    	public String onConfirmationSubmit(@ModelAttribute("openResidentialAccountTenant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    		System.out.println("in onConfirmationSubmit POST ");
    		if(result.hasErrors()){
    			return "alldone_confirmationShouldntHappen";
    		}
    		return "allDone_confirmation";
    	}
    //	
    }
    ps. Thanks for the note about the code tags

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    As I mentioned before there are no parameters with the name specified in the mapping so it will simply never match...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Oct 2012
    Posts
    4

    Default

    Hi Marten

    Thanks for all your help...
    Just for others, here is my final code that is now working:
    Code:
    FIRST JSP 
    
     <form:form commandName="openResidentialAccountTenant">
     <div id="OpenResidentialAccountTenantForm" > 	
      	<h3><a href="#">Step 1 - Add Customer Information</a></h3>
      	<div id="customerInfo">
     
    	<table border="0" cellpadding="0">
    
    		<tr>
    			<td><b>Customer Information</b></td>
    		</tr>
    etc..
    		<tr>
    			<td><br>
    			<input type="submit" name = "editit" value = "editit" /></td>
    		</tr>		
        </table>
        </div>  
    </div>
    </form:form> 
    
    SECOND JSP snippet
    
    
       <form:form commandName="openResidentialAccountTenant.do">   
     	<div id="submitInfo">
    	<table border="0" cellpadding="0">
    		<tr>
    			<td><br/>
    			  <input type="submit" value="Everything looks okay, please submit"  name = "confirmit" value = "confirmit" />
    			</td>
    		</tr>		
        </table>
        </div> 
        </form:form>     
    _____________________________________
    
    Controller:
    
    package com.servlet.ghesiForms;
    
    
    import javax.validation.Valid;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    
    
    
    
    /*
     *  Configure the class as an MVC controller 
     *
     *  Configure the class to process the url "/enquiry"
    */
    
    @Controller
    @RequestMapping("openResidentialAccountTenant.do")
    public class OpenResidentailAccountTenantController{
    
    
    	
    	@RequestMapping(method=RequestMethod.GET)
    	public String setupForm(ModelMap model){
    		System.out.println("in openResidentialAccountTenant GET");
    		OpenResidentialAccountTenantCommand openResidentialAccountTenant = new OpenResidentialAccountTenantCommand();
    		model.addAttribute("openResidentialAccountTenant", openResidentialAccountTenant);
    		return "openResidentialAccountTenant";
    		
    	}
    	
    	@RequestMapping(method=RequestMethod.POST)
    	public String onSubmitTest(@ModelAttribute("openResidentialAccountTenant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    		System.out.println("in openResidentialAccountTenant Test POST");
    		if(result.hasErrors()){
    			System.out.println(result.getAllErrors());
    			return "openResidentialAccountTenant";
    		}
    		return "openResidentialAccountTenant_confirmation";
    	}
    	
    	@RequestMapping(method=RequestMethod.POST, params = "editit")
    	public String onSubmitEdititParams(@ModelAttribute("openResidentialAccountTenant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    		System.out.println("in openResidentialAccountTenant editit POST");
    		if(result.hasErrors()){
    			System.out.println(result.getAllErrors());
    			return "openResidentialAccountTenant";
    		}
    		return "openResidentialAccountTenant_confirmation";
    	}
    	
    
    
    	@RequestMapping(method=RequestMethod.POST, params = "confirmit")
    	public String onConfirmationSubmit(@ModelAttribute("openResidentialAccountTenant") @Valid OpenResidentialAccountTenantCommand enquiry, BindingResult result){
    		System.out.println("in onConfirmationSubmit confirmation POST ");
    		if(result.hasErrors()){
    			return "alldone_confirmationShouldntHappen";
    		}
    		return "allDone_confirmation";
    	}
    //	
    }
    _______________________________
    XML configuration file
    
    	<servlet-mapping>
    		<servlet-name>ghesiforms</servlet-name>
    		<url-pattern>*.do</url-pattern>
    	</servlet-mapping>
    Key here is that the submit button name value pair is providing the uniqueness required for the correct mapping to the corresponding request mapping params values.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •