Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring MVC controller Form

 
Steve Palmer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Steve Palmer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Session attributes are accessible in your Controller which is your regular Java class.
 
Steve Palmer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry I should have said it clearly... Regular Java class which is not a Controller.
 
Tommy Delson
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic