wood burning stoves 2.0*
The moose likes Spring and the fly likes Spring MVC controller Form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring MVC controller Form" Watch "Spring MVC controller Form" New topic
Author

Spring MVC controller Form

Steve Palmer
Greenhorn

Joined: Aug 29, 2011
Posts: 3
Folks, Long time viewer first time poster here on Javaranch. My issue is I am submitting a form that hits the method attached below. I am successfully fetching the value sent from the JSP form. My problem is to make this value available to another class. Lets call this class Sample.java.
How do I make the values submitted from the JSP form available to class Sample.java and keep it there for use until the user logs out.
I tried adding a public String variable in Controller method shown below and then creating an instance of Controller in Sample.java to get the value but it always returns a null.
Help much appreciated.

Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206
Simple enough if you know how to set and get from the session. Check out Spring document and other sources for more info...


In your controller use the following:

Example,


OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
Steve Palmer
Greenhorn

Joined: Aug 29, 2011
Posts: 3
Tommy, thanks for the reply. I was just thinking about doing the session way. Session attributes are accessible in a regular java class?
Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206
Yes, Session attributes are accessible in your Controller which is your regular Java class.
Steve Palmer
Greenhorn

Joined: Aug 29, 2011
Posts: 3
I am sorry I should have said it clearly... Regular Java class which is not a Controller.
Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206
If you use MVC then your regular class is your domain class, you only access and use session in your Controller. Domain object is an Entity or your Model where you declared your members such as instance variables and getter and setter methods.

Seem like you're new to Spring and not understand how MVC works, refer to Spring doc for more details and learn how MVC works.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC controller Form
 
Similar Threads
"on page load" in JSF
MVC 2.5 - How to get the MessageCodesResolver from within a Controller?
error occuring while use jsp
Urgent: How to use Indexed Properties
Getting error when submitting form using SpringMVC and REST