This week's book giveaway is in the Security forum.
We're giving away four copies of Securing DevOps and have Julien Vehent on-line!
See this thread for details.
Win a copy of Securing DevOps this week in the Security forum!

Amir Ghahrai

Ranch Hand
+ Follow
since Jun 19, 2002
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 Amir Ghahrai

hi,
I'm using a JSP page to call a servlet which accesses a database and retrieves some data.
on my JSP pages, I want to show 5 sets of data on each page, where users can see the next set of data by clicking a button or a link to the net page.
my question is that when I connect to database, and get all of the data, can I store the data somewhere as an object so that for the next set of data on another page, I don't have to open the database connection again?
Would sessions in this case solve the problem?
answers would be appreciated.
Deepak,
As regards with your first question, I doubt that the session gets stored in the database. Your session gets stored in a variable called jsessionid which in turn can either be stored on the server or as cookies in the client's machine.
For question 2, Once you have declared a HttpSession variable, you can gain access to it and retrieve its value. Ofcourse you can define the scope (request, page, application) for your session, so that you don't need to rewrite the code everytime in every page. all you have to do is to retrieve its value on each page to identify the source of request.
I suggest encoding all your links (anchor tags) so that when cookies are disabled on client's browser, then URL-rewriting is taken over automatically. You can try this by disabling cookies on your machine and then focus on the web address bar on your browser. each time you make a request, the jsessionid is appended to the url and any query strings, provided that you have encoded your links.
HTH
14 years ago
JSP
Hello,
is it possible to force url re-writing even if the browser allows cookies?
As I understand, when encoding URL's, the default method is that the session is stored in cookies, if the browser accepts cookies, and url re-writing is used (automatically) in cases when the browser refuses to accept cookies.
I want to know if url re-writing can be forced in cases where the browser accepts cookies?
14 years ago
JSP
Ok, the problem was not in the getItemByID method but in the Item class.
In the Item class, I had declared the variables as static and ofcourse each time, the methods were calling on the same value as before, and not instantiating Item objects with different values.
(Ofcourse it took me 3 days to notice this!)
14 years ago
Joel, and Jim,
Thanks for youe answers. I will definately look into it more closely. but just for clarity, I have included the getItemByID methos below

This method is suppose to return an item object given the ID of the item.
The two dimensional array is filled from a while loop for resultset object and the capital letters are constants for clarity.
I didn't seem to get problems with this method, cause I tried it numerous times, but when I call it from getCatalog method, it fails.
[ June 28, 2003: Message edited by: Amir Ghahrai ]
[ June 28, 2003: Message edited by: Amir Ghahrai ]
14 years ago
I have a method similar to the one shown below

suppose I have 5 items.
Inside the 1st for loop, the code that prints out the name of each item seems to be fine, but inside the 2nd for loop, it will print only the last element 5 times. In other words, the vector seems to "reset" each time and the value I get returned is a vector with the last value stored from the for loop, and not a vector of different values.

Any suggestions to fix this?
14 years ago
Not a problem with the session then, as the subject of the post indicate!
14 years ago
JSP
Harish,
normally a session is terminated when you close your browser. therefore if you try to access the same page in a newly opened browser, the site will not give you access because there is no session associated with your browser.
You can define a session in your JSP page to keep track of users.
//a new session
HttpSession session = req.getSession(true);
//get the value of session
String x = (String) session.getAttribute("Object")
if(x == null) {
// redirect the user to another page
}
else {
// forward the user to the requested page
}
HTH
14 years ago
JSP
Hi,
I don't know of any tools that can be used, but you can include few code in your JSP page to do the debugging.
Try the link below:
http://www.macromedia.com/support/ultradev/ts/documents/jsp_debug.htm
HTH
14 years ago
JSP
Hi Bill,
After much scrutiny of my code, I finally could see where the problem is coming from. I have a method similar to the method below

suppose I have 5 items.
Inside the for loop, the code that prints out the name of each item seems to be fine, but outside the for loop, it will print only the last element
5 times. In other words, the vector seems to "reset" each time and the value I get returned is a vector with the last value stored from the for loop, and not a vector of different values.
sample output
14 years ago
JSP
Bill, thanks for your reply. This is exactly what is happening, but I cannot see where in my code I am going wrong.
I will describe a little bit more about the application.
I have an Item class which has a list of get/set methods that represent the properties of an item, such as name, description, price as well as a unique ID.
I also have a Catalog class which retrieves the Item data from the database and stores them in an array.
This class has two methods, one which returns an array of product ID's, and another method which instantiates an Item object for a given product ID,

in my Shopping cart class I have an addItem method which takes the productID as a String parameter and constructs an Item object and adds it to the Vector.
(I am guessing that this is where the problem occurs, that it overwrites the previous Item objects)

Hope this will clarify my problem.
Thanks for your help.
14 years ago
JSP
Hi,
Is there anyway to force URL re-writing even if the browser on the client accepts cookies?
When using URL encoding, the default is to store the session in cookies (if cookies are enabled),
but how do you force URL rewriting even with cookies enabled?
Thanx
14 years ago
Bill,
Basically, I'm using a Vector to store the items.
I have thought about using a Hashmap instead, but the book that I'm following the example from, uses a Vector to store the shopping cart items in it.
14 years ago
JSP
Hi,
Is there anyway to force URL re-writing even if the browser on the client accepts cookies?
When using URL encoding, the default is to store the session in cookies (if cookies are enabled),
but how do you force URL rewriting even with cookies enabled?
Thankx
Hi,
I am developing a simple shopping cart application, using JSP and servlets.
my problem is that whenever, I add an item to the cart, it overrides the previous ones.
For instance, when I view the cart with 1 item in it it will show,
number of items 1, item1
when I add a second item it will show
number of items 2, item2, item2.
instead of printinh
number of items 2, item1, item2.
I cannot see where this problem is coming from.
any suggestions?
Thanks
14 years ago
JSP