aspose file tools*
The moose likes Servlets and the fly likes Refresh problem in JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Refresh problem in JSP page" Watch "Refresh problem in JSP page" New topic
Author

Refresh problem in JSP page

Yongping Wang
Ranch Hand

Joined: May 15, 2001
Posts: 40
Dear everyone:
Here is the problem I encountered. (My OS is NT4.0 and server is Weblogic5.1, SP7). I use a session to store an object (user defined type) in servlet (processing results from database) then dispatch to a jsp page to display the results.
The segment of servlet code:
========================================================
HttpSession session = req.getSession(true);
Vector temp = buildData.BuildForDisplay(rst);
session.setAttribute("PostTitlePool", temp);
String url = "/ccproject/subdisplay.jsp";
RequestDispatcher dis = getServletContext().getRequestDispatcher(url);
dis.forward(req, res);
====================================================
JSP code:
----------------------------
<%@ page import="com.voy.CCPro.*" %>
<%@ page import="java.util.*" %>
<%
Vector v = new Vector();
v = (Vector)session.getAttribute("PostTitlePool");
Enumeration enum = v.elements();
SequenceData sq = new SequenceData();
while(enum.hasMoreElements())
{
sq = (SequenceData)enum.nextElement();
if(sq.getIndicator()==0)
{
out.println(sq.getTitle());
}
else
out.print(sq.getTitle());
}
%>
-----------------------------------------------
My code works but not perfect because I got strange
result from browser if I keep on clicking refresh/reload (IE5.5/Netscape), the same result appending
the previous one on the same page.
Please explain it to me why that and how to fix it. Many thanks.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

What does this line do?

Vector temp = buildData.BuildForDisplay(rst);

If rst is something you've retrieved from the session or request -
More specifically if it's
Vector rst = (Vector) req.getAttribute("PostTitlePool");

and if inside the BuildForDisplay function you simple add to the existing vector, then you will be concatenating your previous Vector onto the Vector you then stick into

session.setAttribute("PostTitlePool", temp);

And your output will be increasing and increasing as you've descirbed.
Yongping Wang
Ranch Hand

Joined: May 15, 2001
Posts: 40
Originally posted by Mike Curwen:
What does this line do?

Vector temp = buildData.BuildForDisplay(rst);

If rst is something you've retrieved from the session or request -
More specifically if it's
Vector rst = (Vector) req.getAttribute("PostTitlePool");

and if inside the BuildForDisplay function you simple add to the existing vector, then you will be concatenating your previous Vector onto the Vector you then stick into

session.setAttribute("PostTitlePool", temp);

And your output will be increasing and increasing as you've descirbed.

rst is ResultSet retrived from database. Function BuildForDisplay is used to sort and reorganize the result. Any suggestion to fix it? Thanks a lot again

[This message has been edited by Yongping Wang (edited May 17, 2001).]
saravanakumar sundaram
Greenhorn

Joined: May 16, 2001
Posts: 5
The problem could in the vector only as the vector contents gets appended everytime you call buildData.BuildForDisplay(rst) function.
try one thing. try to make that vector empty after the processing and see.
Yongping Wang
Ranch Hand

Joined: May 15, 2001
Posts: 40
Originally posted by saravanakumar sundaram:
The problem could in the vector only as the vector contents gets appended everytime you call buildData.BuildForDisplay(rst) function.
try one thing. try to make that vector empty after the processing and see.

Yes, you are right. The problem is vector in BuildForDisplay(). If I change to use Array, the problem is gone. But I still can't figure out why vector in BuildForDisplay function keep previous elements 'cause each time a new vector is created if the function is invoked. Anyway thanks a lot again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Refresh problem in JSP page