Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Frank Sikuluzu

Ranch Hand
+ Follow
since Dec 16, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Frank Sikuluzu

Originally posted by Tim Baker:
I understand what you are saying.

Another issue to consider is that anything you keep in hidden fields on the page can be altered by an end user, so anything you get back from hidden fields should not be trusted.

.



Want to know how end user can modify the hidden variables. I thought the page is on the server. Could you describe some details ?

thanks.
15 years ago
Session eats memory and most servers have the swapping featur that swap the session from memory to disk, this will cause performance slowdown. Thus, I am hesitating if I should use "session" to or "request" to store and carry objects over pages. If I use "request" I will use hidden variables to carry all the objects over pages so it is more burdensome for programming. But if the objects stored in "request" will never be swapped to disk, then using "request.setAttribute" and hidden variable can gain performance advantage. Do I make sense here ?
15 years ago

Originally posted by William Brogden:
Servlet containers are allowed to Serialize sessions to disk or other storage so they do NOT have to keep all active sessions in memory. Thats why you should ensure that all objects "stored" in sessionss should implement Serializable.
Bill



How about HttpRequest ? will there be any chance that requests are serialized to disk ? I guess not, but not sure. Please confirm if you know the answer.

By the way, sessions are first stored in memory so it consumes memory. Where are "requests" stored ? Do they also eat memory ?
15 years ago
I heard that session is defined as --- If they are from the same machine within a certain duration of time, the server consider the sessions as the same. Now I am wondering about the following interesting scenarios ---

1. If I have JSP1-->servlet-->JSP2-->servlet-->JSP3, on JSP1 we have five radio button and I pick button 1, in my servlet code I have

***********************
public class Servlet extends ...{

request.getSession().setAttribute("choice", request.getParameter("choice"));

**********************

i.e. I SAVE this choice of JSP1's radio button in the "session" object, then I go to JSP2, I pick button 1 again, then I click "back" which brings me back to JSP1, this time I click button 2 instead, will the server mistakenly think I am still in the "last" session. If this is true, then server will mistakenly pick the "choice" value from last time, i.e. even I pick button 2 this time, the server will get the "choice" value as of button 1's.

2. what if I open two windows on my desktop, will they mess up with each other ?
15 years ago
JSP
Thanks Ben. Actually I am more concerned with the one window scenario like --- If I have JSP1-->Action1-->JSP2-->Action2--->JSP3-->Action3, each Action contains "req" and "res" instances. And while it flows as this, I use session.setAttribute to memorize what I select in each page, now I want to understand this --

1. when I finish JSP1, JSP2, and JSP3 and immediately clikc "back","back" to JSP1 and restart selction from there, at this moment will server create a new session for me or will I get the same session as I just finished with JSP3 ???

2. Following up question, suppose I go through JSP1, JSP2, and JSp3, then immediately click "back" to JSP2 and start picking a different item, will the server immediately give me a new session or what ?

[Bear edit: Bear/Ben, separated at birth?]
[ June 21, 2005: Message edited by: Bear Bibeault ]
15 years ago
JSP
I heard that session is defined as --- If they are from the same machine within a certain duration of time, the server consider the sessions as the same. Now I am wondering about the following interesting scenarios ---

1. If I have JSP1-->servlet-->JSP2-->servlet-->JSP3, on JSP1 we have five radio button and I pick button 1, in my servlet code I have

***********************
public class Servlet extends ...{

request.getSession().setAttribute("choice", request.getParameter("choice"));

**********************

i.e. I SAVE this choice of JSP1's radio button in the "session" object, then I go to JSP2, I pick button 1 again, then I click "back" which brings me back to JSP1, this time I click button 2 instead, will the server mistakenly think I am still in the "last" session. If this is true, then server will mistakenly pick the "choice" value from last time, i.e. even I pick button 2 this time, the server will get the "choice" value as of button 1's.

2. what if I open two windows on my desktop, will they mess up with each other ?
15 years ago
JSP
I guess you're right. But I have never tried that.
15 years ago
I created a HashMap putting values and keys, the keys are like "01", "02", "03" kind two digits string. The when I loop through the HashMap, I use

Set set= hm.keySet();
Iterator iter = set.iterator();
while(iter.hasNext()){
String currentKey = iter.next();
// print out this currentKey
}

The print out result shows it is NOT ordered by "01", "02", "03" or alphabetical letter order, which was what I expected.

Why ? and how do I get a loop that output keys in alphabetical letter or digital ascendant order ?
15 years ago

Originally posted by Bear Bibeault:


No. Regardless of whether you use a session anywhere, the container manages it.

Never create a session on your own. Never. Ever.



Then, under what circumstance should I use "HttpSession = new HttpSession();" ?
15 years ago
JSP

Originally posted by Ben Souther:
Don't ever use new to get a session.

In your JSP use the "session" variable created for youby the container.
In the servlet, use request.getSession().

Always let the container handle the creation of the session.



But if I do not use any session in JSP1, do I need to use "new" to create one in the servlet or Action ?
15 years ago
JSP
Please allow to ask a follow-up question. If "session" is an implicit thing server creates for me, then in my JSP1-->Servlet-->Action-->JSP2 process, In the "Action" class the "execute(request, response)" method involves adding some new attirbutes to the session. Now the question are --

1. If I use "session.setAttribute("name", myVar) in the JSP1, then in "Action" class I can NOT use "HttpSession session = new HttpSession();" any more, right ? I can only add attributes like "request.getSession().setAttribute("name2," anotherVar);", is this right ?

2. If I don't do anything with session in JSP1, then in "Action", do I need to write "HttpSession session = new HttpSession();" before I add attributes. It seems Yes, right ? Then I am confused, why ? it seems there is already "session" created by the server in JSP1, so why can't I just directly use it in "Action" ?
15 years ago
JSP
If I want to create a HttpSession in my index.jsp (the first page of application), should I just do

<% HttpSession session = new HttpSession();
session.setAttribute(..);
%>

But it seems "session" is an "implicit" JSP object. So I am wondering do I still need to instantiate it formally before I add attributes to it ?
15 years ago
JSP
want to test Httpsession tracking. how to turn off the cookie for an IE browser ?
15 years ago
so,

1. do you mean that, if I use struts, I do NOT need to write any code syntax like "encodeURL" anywhere ??

2. When you say it is automatic, do you mean if the browser doesn't support cookie, the URL will automatically be appended by a "jsessionid=.." ?
15 years ago
please bear with me for few more questions ---

1. why don't I need to do "encodeURL" if it is "forward(req, res)" to a JSP page ? is it because I use "forward" or because it is to a JSP or servlet ?
Since I need to use "req.getSession" to get the HttpSession I feel I still need to do encodeURL in this case. Please help me clarify.

2. What if I , for safety reason, just use "encodeURL" anyway when I do "forward()", does it cause any extra harm ?

3. if it is a JSP page and there is a FORM

<FORM ACTION="/servlet/MyServlet"..>

And there is a session involved in this JSP page and certainly I would like to carry the session after I clic "sumbit" button. How do I apply "encodeURL" in the ACTION tag ?
15 years ago