> -----Original Message-----
> From: Caroline Jen [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 01, 2004 10:00 PM
> To: [EMAIL PROTECTED]
> Subject: Pass a Variable From JSP via JSP To an Action Servlet
> 
> 
> I have the value of a variable defined in JSP#1 (JSP#1
> is not a form):
> 
>    <c:set var="id" value="${articleForm.article}"
> scope="session"/>

It's not a variable... it's a bean ie an object.

> 
> 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.

If the bean id is not defined in jsp2, it's not being forwarded.
See below for why.

> 
> 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.

That's why you think it's being "forwarded". It's in session scope.
If you put it in the request scope, it will only live for the request, so your
action after the submit won't even know it exists.

> 
> 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 

Yes.. all request/session/application level attributes are beans.. which means they
are objects.  If you put an int (as you do for the id), it's not an int, it's an 
Integer.

Your questions indicate that you are used to either ASP, or PHP style programming.  
JSP/Servlet technology is not anything like what I've seen as typical of those 
environments.  Please do yourself a favor and educate yourself on the technology.  All 
of your questions so far would be answered by any online tutorial or article on basic 
JSP/Servlet technology.  


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to