• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Refresh problem in JSP page

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic