pronane
asked on
Difference between session and request
What is the difference between session and request parameters, does session just last for any given users session whereas request lasts for any user? how do you set the session and request etc
I know that with the request parameter everything is an object within the
request.getParameter()
is this the same with session
session.getAttribute().
Also can you set the Parameter with request, and what are you really doing when you set the parameter/setAttribue?
Finally, when you do setAtrribute(test, "test");
where
String test = "tester";
which variable are u setting and which one will u be using in the page that gets the attribute, i.e where session.getAttribute(_what _goes_here _) is called.
_what_goes_here_ = ??
Im hoping that someone will actually explain this rather than just give me a site, if i get an explanation then i will give 100 points for the question. As ive read it before but i dont fully understand, so an answer with a backup link would be great.
Thanks,
Paul
I know that with the request parameter everything is an object within the
request.getParameter()
is this the same with session
session.getAttribute().
Also can you set the Parameter with request, and what are you really doing when you set the parameter/setAttribue?
Finally, when you do setAtrribute(test, "test");
where
String test = "tester";
which variable are u setting and which one will u be using in the page that gets the attribute, i.e where session.getAttribute(_what
_what_goes_here_ = ??
Im hoping that someone will actually explain this rather than just give me a site, if i get an explanation then i will give 100 points for the question. As ive read it before but i dont fully understand, so an answer with a backup link would be great.
Thanks,
Paul
ASKER
how do you create a session for a user?
One is automatically created with JSPs
<%
out.println( "<H1>" + session.getId() + "</H1>" ) ;
%>
out.println( "<H1>" + session.getId() + "</H1>" ) ;
%>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what is the point in passing this then
loggedInUser
and this
resultList
if this is never accessed in the jsp that willl get the attributes??
loggedInUser
and this
resultList
if this is never accessed in the jsp that willl get the attributes??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Request is something which comes in handy when you are moving from one page to another by submitting a form. Whereas session is something that exists unless you explicitely remove it or the browser gets closed.
the diff between request.getParameter() and session.getAttribute() is that the latter gives you access to the attribute value whereas the former one gives you the object reference for wat you would have set.
the diff between request.getParameter() and session.getAttribute() is that the latter gives you access to the attribute value whereas the former one gives you the object reference for wat you would have set.
> the diff between request.getParameter() and session.getAttribute() is that the latter gives you access to the attribute value whereas the former one gives you the object reference for wat you would have set.
No, request.getParameter() gets a value out of the URL query (POST header or GET URL)
You mean request.getAttribute()
No, request.getParameter() gets a value out of the URL query (POST header or GET URL)
You mean request.getAttribute()
ASKER
no tim i dont think you understood what i was saying
why dont u just pass
"queryResults" and "userName"
because they are the variables that are always accessed
not
loggedInUser or ResultList
do you follow me? what is the point in passing both names in???
why dont u just pass
"queryResults" and "userName"
because they are the variables that are always accessed
not
loggedInUser or ResultList
do you follow me? what is the point in passing both names in???
> do you follow me?
Not sure....
> what is the point in passing both names in???
Into the setAttribute() method?
The first parameter is the name you want to give to the attribute
The second parameter is the attribute itself
int[] intarr = new int[ 3 ] ;
session.setAttribute( "ARR", intarr ) ;
intarr is the attribute, I have stored it in the session under the name "ARR"
so in another jsp, I can do:
int[] intarr = (int[])session.getAttribut e( "ARR" ) ;
and get the array back out again...
Hope I understood the question right...
Not sure....
> what is the point in passing both names in???
Into the setAttribute() method?
The first parameter is the name you want to give to the attribute
The second parameter is the attribute itself
int[] intarr = new int[ 3 ] ;
session.setAttribute( "ARR", intarr ) ;
intarr is the attribute, I have stored it in the session under the name "ARR"
so in another jsp, I can do:
int[] intarr = (int[])session.getAttribut
and get the array back out again...
Hope I understood the question right...
ASKER
ya thats what i was aksing alright
why cant u just pass the name of the attribute though without having to pass the both?, that is my real question.
i.e
String paul = "t"
session.setAttribute( paul)
and is it the same for setParameter etc?
i.e request.getParameter("paul ", paul);
?
why cant u just pass the name of the attribute though without having to pass the both?, that is my real question.
i.e
String paul = "t"
session.setAttribute( paul)
and is it the same for setParameter etc?
i.e request.getParameter("paul
?
> why cant u just pass the name of the attribute though without having to pass the both?, that is my real question.
Because at run time, java has no idea what you called your variables. Variable names are there to help you keep track of what is what, but java doesn't care about what you called them, so that information is gone when the JSP is compiled...
Therefore, you have to give them a name.
> request.getParameter("paul ", paul);
You mean
request.getAttribute( "paul" );
;-)
request.getParameter( String parametername )
gets a parameter from a form post :-)
Tim
Because at run time, java has no idea what you called your variables. Variable names are there to help you keep track of what is what, but java doesn't care about what you called them, so that information is gone when the JSP is compiled...
Therefore, you have to give them a name.
> request.getParameter("paul
You mean
request.getAttribute( "paul" );
;-)
request.getParameter( String parametername )
gets a parameter from a form post :-)
Tim
ASKER
sorry no i meant
request.setParameter("paul ", paul);
not
request.getParameter("paul ", paul);
request.setParameter("paul
not
request.getParameter("paul
> request.setParameter("paul ", paul);
You can't do that, what you mean is:
request.setAttribute( String name, Object value ) ;
Attribute, not parameter...
Parameter is for gettting values posted to the page by a form
You can't do that, what you mean is:
request.setAttribute( String name, Object value ) ;
Attribute, not parameter...
Parameter is for gettting values posted to the page by a form
ASKER
ok tim you have answered sufficiently so i will give u the points, before i do i was just wondering if you could briefly explain what this is doing:
<input type="checkbox" name="linkDeleteCB<%=k%>"
<%
if ( linkDeleteCB.equals( "on" ) )
{
%>
checked="true"
<%
}
%>
where k is any number, what does it mean by name = linkDeleteCB<=%k> ?
this really is the last question!
<input type="checkbox" name="linkDeleteCB<%=k%>"
<%
if ( linkDeleteCB.equals( "on" ) )
{
%>
checked="true"
<%
}
%>
where k is any number, what does it mean by name = linkDeleteCB<=%k> ?
this really is the last question!
Assuming k is an index in a for loop, the above code fragement will produce HTML to the client like this:
<input type="checkbox" name="linkDeleteCB1">
<input type="checkbox" name="linkDeleteCB2">
<input type="checkbox" name="linkDeleteCB3">
<input type="checkbox" name="linkDeleteCB4" checked="true">
<input type="checkbox" name="linkDeleteCB5">
<input type="checkbox" name="linkDeleteCB6">
(I cleaned up the whitespace in the actual results)
<input type="checkbox" name="linkDeleteCB1">
<input type="checkbox" name="linkDeleteCB2">
<input type="checkbox" name="linkDeleteCB3">
<input type="checkbox" name="linkDeleteCB4" checked="true">
<input type="checkbox" name="linkDeleteCB5">
<input type="checkbox" name="linkDeleteCB6">
(I cleaned up the whitespace in the actual results)
ASKER
ok thanks and checked = true on the 4th one
means assuming the the 4th one checkboxed is checked it will delete whatever value that represents?
Can i half the points or give assisted answers as both you and tim ahve answered in the questions?
means assuming the the 4th one checkboxed is checked it will delete whatever value that represents?
Can i half the points or give assisted answers as both you and tim ahve answered in the questions?
There is a "Split points" link above the comment entry box on this page :-)
Then you can divide the points up between us :-)
Then you can divide the points up between us :-)
session variables retain state throughout the users session (if you create one)