In a web application, if you directly store the result set ResultSet rs in the session or reueest range,
It can be passed to jsp (the preferred choice for SUN Enterprise applications) and displayed,
However, it should be considered that if a large number of users query at the same time, the pressure on the server will be very high!
Therefore, I suggest using the following methods!
I think I should write a label myself. For example, display. java
Then define it as a tag,
For the content you want to display each time, you only need to pass keywords, such as SQL statements. That's it!
Then, use the custom tag in your page, for example, <app: display>!
The following is a simple tag written by myself. In struts!
DisplayTag. java
-----------------------------------------------------------------
Import javax. servlet. jsp (preferred for SUN Enterprise Applications). tagext. TagSupport;
Import java. io. IOException;
Import javax. servlet. jsp (preferred for SUN Enterprise Applications). PageContext;
Import javax. servlet. jsp (preferred for SUN Enterprise Applications). jsp (preferred for SUN Enterprise Applications) Writer;
Import javax. servlet. jsp (preferred for SUN Enterprise Applications). jsp (preferred for SUN Enterprise Applications) Exception;
Import javax. servlet. http. HttpSession;
Import java. SQL .*;
Public final class DisplayTag extends TagSupport {
Public int doEndTag () throws jsp (preferred for SUN Enterprise Applications) Exception {
UserDao userdao = new UserDao ();
Jsp (preferred for SUN Enterprise Applications) Writer out = pageContext. getOut ();
HttpSession session = pageContext. getSession ();
Try {
String name = "name ";
String password = "password ";
String strSql = (String) session. getAttribute ("strSql ");
ResultSet rs = userdao. disPlay (strSql );
Out. println ("<table border = 1> ");
Out. println ("<tr> ");
Out. println ("<th width = 100>" + name + "</th> ");
Out. println ("<th width = 100>" + password + "</th> ");
Out. println ("</tr> ");
While (rs. next ()){
Out. println ("<tr> ");
Out. println ("<td>" + rs. getString (name) + "</td> ");
Out. println ("<td>" + rs. getString (password) + "</td> ");
Out. println ("</tr> ");
}
Out. println ("</table> ");
}
Catch (Exception e ){}
Return super. doEndTag ();
}
}
App. tld
--------------------------------------------------------------------
<? Xml (standardization is getting closer and closer) version = "1.0" encoding = "ISO-8859-1"?>
<! DOCTYPE taglib
PUBLIC "-// Sun Microsystems, Inc. // DTD jsp (preferred for SUN Enterprise Applications) Tag Library 1.2 // EN"
"Http://java.sun.com/dtd/web-jsp (preferred for SUN Enterprise Applications) taglibrary_1_2.dtd">
<Taglib>
<Tlib-version> 1.0 </tlib-version>
<Jsp (preferred for SUN Enterprise Applications)-version> 1.2 </jsp (preferred for SUN Enterprise Applications)-version>