File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Unable to call Controller method after form submission using Spring MVC 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Unable to call Controller method after form submission using Spring MVC 3" Watch "Unable to call Controller method after form submission using Spring MVC 3" New topic
Author

Unable to call Controller method after form submission using Spring MVC 3

Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
Hi,

I am a newbie to spring mvc. I have a employee form, which after filling 'submit's to an action, which is mapped to a Java Controller. However, the method is not being invoked. Can anyone help with the same?

Please find the attached code snapshots below.

Controller method signature


jsp form


spring configuration xml - view resolver definitions


Can anyone tell me how do I invoke the Java Controller method from the .jsp page ?
Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
Can anyone help?

I have a feeling it has probably go to do something with the View resolvers. If I change the action="addEmployee" to action="addEmployee.do", the web server goes and searches for a page /WEB-INF/jsp/addEmployee.jsp!

What I want is for the link addEmployee to be resolved to /addEmployee which I have already annotated in my controller.
Hongli Li
Ranch Hand

Joined: Oct 29, 2006
Posts: 124
how do you map your dispatcher controller, in web.xml, I assume you used .do as the pattern, so you action have to be sufixed with .do, otherwise spring won't intercept it for you.


Do you know why this cup is useful? Because it is empty.
Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
Hi Hongli Li,

Please read my earlier post.

Yes, I have a dispatcher servlet with .do pattern. However, if I add .do as the extension, it searches for the following resource /WEB-INF/jsp/addEmployee.jsp due to the View Resolver configuration.

Instead, what I want is for the link to be mapped to a Controller which is annotated with
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

Can you please show us your web.xml?


Regards, Prasad
SCJP 5 (93%)
Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
Here's my web.xml


This is my spring configuration file


PS: The BeanNameViewResolver may or may not be necessary. I was just trying a couple of things and hence have added this entry.
Dharmakumar Gajendran
Greenhorn

Joined: Feb 22, 2010
Posts: 20
1. In jsp file add '.do' to the action action="addEmployee.do"
2.In the Spring config file add the mapping for this url
<bean name="/addEmployee.do" class="<give your controller class location with full package structure>"/>

Try this and let me know.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 507

You are mapping *.do requests to spring dispatcher servlet.. but in jsp file you are just calling addEmployee, then how are you expecting the spring servlet to handle this request for you.. change addEmployee to addEmployee.do in jsp file as well as @Requestmapping.. it should work..
Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
@Dharmakumar
2.In the Spring config file add the mapping for this url
<bean name="/addEmployee.do" class="<give your controller class location with full package structure>"/>

If I do this, my tomcat crashes during startup with the following error


@Prasad Krishnegowda
I had earlier tried doing that, but the request addEmployee.do was being resolved to /WEB-INF/jsp/addEmployee.jsp which is my default ViewResolver configuration in spring config file.

However, I tried the same again right now and it has worked. I have no idea why it had not worked the first time and why was it going to the ViewResolver earlier.

Anyway, thanks for your help!
Fatima Joseph
Greenhorn

Joined: Jun 29, 2011
Posts: 1
Were you able to resolve this. I am having the same problem. I am trying call the controller from a jsp. I am not sure how to write this mapping in the Spring Config file.
 
wood burning stoves
 
subject: Unable to call Controller method after form submission using Spring MVC 3
 
Similar Threads
New value is inserted into db in @ManyToOne relation instead of update
Spring MVC 3: java.lang.IllegalStateException
Validation not working
Problem with validation example
Client side validation not working