• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Passing variable from controller to controller

Ranch Hand
Posts: 88
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone, I was going through "viralpatel.net" website to learn Spring3. So far things were good till the time I was planning to do something different as follows. As I am stuck here, therefore seeking help from you all. Please tell me where is my problem. Always thankful to you guys.

UseCase: I have three JSP pages. First one "index.jsp" is just redirecting the App to "contact.jsp" page. "contact.jsp" is a form page where user submit their info. As soon as they will submit the form, the app will bring the user to another page "hello.jsp", where the App will print welcome message as well as user firstname. For "contact.jsp", I am using "ContactController.java" < as my Controller class and "Contact.java" < as the for bean for this App and for "hello.jsp", I am using "HelloWorldController.java" < as another controller class.

Problem: From controller "ContactController.java", I can redirect the App to "hello.jsp" where "HelloWorldController.java" nicely playing its role and printing the message as the code I am presenting below but when I am trying to pass the firstname or lastname or any other info from "ContactController.java" controller to "HelloWorldController.java", then getting error. Sometimes "hello.jsp" is coming just like a blanck pageand showing nothing.

So here I don't know how to pass variables and their values from one controller to another in Spring3. Will be glad also if any one can help me to get some tutorials on this please.

a) web.xml

b) spring-servlet.xml

c) index.jsp

d) contact.jsp

e) hello.jsp

f) ContactController.java

g) Contact.java

h) HelloWorldController.java

Note: The above code is working absolutely fine when I am commenting out this line: //String message = new ContactController().firstName; from "HelloWorldController.java".
Question is why I can't access any elements from "ContactController.java" or what is the right way to do so? Thanks again
Faisal Fuad
Ranch Hand
Posts: 88
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok...I solved it! I did the following changes only:

In the "ContactController.java" I did the following:

Notice that I added Map<String, Object> map in the addContact method parameter. And also point out the secuence I am following to declare those parameters. You will get "Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!" Error Message if you don't follow this siquance. A nice article I found here: LoonGest

And in "hello.jsp" page, I just did this:

Rest of the files are all same. Great !!
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic