This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes Pass a Variable from JSP via JSP to an Action Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Pass a Variable from JSP via JSP to an Action Servlet" Watch "Pass a Variable from JSP via JSP to an Action Servlet" New topic
Author

Pass a Variable from JSP via JSP to an Action Servlet

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I am using the Struts framework.

I have the value of a variable defined in JSP#1 (JSP#1 is not a form):

All the variables, which are defined in JSP#1, are forwarded to JSP#2.

JSP#2 is a form. But, the variable 'id' is not used in JSP#2.

JSP#2 has a submit button and then, an action servlet takes over the control. All the text fields in JSP#2 together with the variable 'id' are forwarded to this action servlet.

I have two questions:

1. I should put this variable 'id' in the request scope or the session scope. Currently, it is in the session scope.

2. How to retrieve the value of this variable 'id' in the action servlet? (I do not want to print the value out. I want to retrieve the value and store it in a database.)

session.getAttribute( "id" ); // returns an object. 'id' should be an integer
[ July 01, 2004: Message edited by: JiaPei Jen ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Pass a Variable from JSP via JSP to an Action Servlet