Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prasad Shindikar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please show us your web.xml?
 
Prasad Shindikar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Whatever. Here's a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!