Sorry ASC...

You keep the results of the query in a similar style - you can store pretty much
any object on the session (not too sure about ResultSet though). So you could, for
instance, put the relevant data into a vector and store that on the session if that
suits the kind of data the query returns. e.g.:


// once you've established your query

ResultSet rs = jdbc.createStatement().executeQuery(query);
ResultSetMetaData meta = re.getMetaData();
int cols = meta.getColumnCount();

Vector vector = new Vector();
while(results.next()) {
    String[] entry = new String[cols];
    // maybe build the first html page in here too
    for(int i = 0;i < cols;i ++) {
        entry[i] = results.getString(i + 1);
    }
    vector.addElement(entry);
}

session.putValue("results",vector);

.
.
.

// then to retrieve the data

Vector vector = (Vector)session.getValue("results");
for(int i = 0;i < vector.size();i++) {
    String[] entry = vector.elemntAt(i);
    // output it into whatever format
}


Hope that is of more use. I make no excuses for the quality (or lack thereof) the
above code but it works :)

Simon


ASC wrote:

> Yes, I know about session tracking, and I can keep the identity of an user. The
> problem is: how I keep the results of the query?
>
> Simon Christian wrote:
>
> > This is a fairly major part of using servlets - session tracking. Check out
> > the HttpSession class, which allows you to store objects which relate (via
> > the SessionId) to individual users. This requires that users either allow
> > cookies, or on URL rewriting.
> >
> > I'd put some example code but like I say it's a major part and worth reading
> > up on properly.
> >
> > Simon
> >
> > ASC wrote:
> >
> > > A few days ago I asked in this list about using JavaMail or sun smtp
> > > classes. I have decided to use JavaMail classes. (for the only reason
> > > that I already have the jars ,and it is not so complicated as it seemed
> > > - to me, at least). Thanks to all that made their comments.
> > > Now I need a solution for the problem of mail. The idea is simple: the
> > > user requests certain information to a servlet, which retrieves it from
> > > a DB. I want the user can obtain a plain text file with the results of
> > > the query, if he/she wants. (pressing a button,i.e.) The results are
> > > also diplayed in the page returned by the servlet. A solution is to make
> > > a call to a different servlet that performs the same query, but doesn't
> > > return a page, but sends a mail. But it requires the query be performed
> > > twice. I would like to mantain in memory the string (really big string)
> > > in the servlet, and depending on the action required, the results are
> > > sent to a writer (browser) or sent via mail, so when the user clicks the
> > > button the same servlet uses the same string. But the problem is that if
> > > I mantain the variable (not declaring it in the service method), can
> > > occur several requests from different users, so the results arn't the
> > > same.
> > > To sum up, I would like receiving some suggestions on how "remember" the
> > > results beetwen two requests from the same user (without write to disk),
> > > or some way to not use two servlet that meke the same.
> > >
> > > Thanks.
> >
> > ___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to