File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Passing variable from controller to controller Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Passing variable from controller to controller" Watch "Passing variable from controller to controller" New topic

Passing variable from controller to controller

Faisal Fuad
Ranch Hand

Joined: Jul 05, 2011
Posts: 83

Hello everyone, I was going through "" 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 "" < as my Controller class and "" < as the for bean for this App and for "hello.jsp", I am using "" < as another controller class.

Problem: From controller "", I can redirect the App to "hello.jsp" where "" 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 "" controller to "", 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




Note: The above code is working absolutely fine when I am commenting out this line: //String message = new ContactController().firstName; from "".
Question is why I can't access any elements from "" or what is the right way to do so? Thanks again
Faisal Fuad
Ranch Hand

Joined: Jul 05, 2011
Posts: 83

ok...I solved it! I did the following changes only:

In the "" 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 agree. Here's the link:
subject: Passing variable from controller to controller
jQuery in Action, 3rd edition