aspose file tools*
The moose likes JSP and the fly likes How to use JSTL instead of scriptlet.This is about JDBC. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to use JSTL instead of scriptlet.This is about JDBC." Watch "How to use JSTL instead of scriptlet.This is about JDBC." New topic
Author

How to use JSTL instead of scriptlet.This is about JDBC.

William Turner
Greenhorn

Joined: Mar 22, 2008
Posts: 2
Sorry,my English is pool.I try my best to express my mind....

I use this scriptlet to display some data form SERVLET:
<table border="1" cellspacing="0">
<tr>
<th>CustId</th>
<th>Email</th>
</tr>
<%ResultSet rset=(ResultSet)request.getAttribute("rset");
if(rset==null){%>
<tr><td>没有数据</td></tr>
<%}%>
<%while(rset.next()){%>
<tr>
<td><%=rset.getString("UserId") %></td>
<td><%=rset.getString("Email") %></td>
</tr>
<%} %>
</table>
How can I use JSTL to instead of this scriptlet?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

JSTL does provide a set of SQL tags but many of us consider it a mistake to have created them. JSTL and EL were meant to give JSP developers just enough capability to work with the results of operations performed in the controller and model tiers in order to mark up the pages. No more.

The SQL tags were added for prototyping, testing, and trivial applications.
From the JSTL specs:


Because the SQL tags violate many of the principal reasons for having JSTL and EL in the first place, many of the experienced developers who frequent this forum don't bother with them at all. As a consequence there are very few people who can answer questions about them.

All that being said, if you still want to use them, I suggest dowloading the spec and reading section 10.
http://jcp.org/aboutJava/communityprocess/final/jsr052/
[ March 22, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
William Turner
Greenhorn

Joined: Mar 22, 2008
Posts: 2
I guess that I could use
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
In fact,I have tried it in the afternoon.
Other codes in JSP:
<sql:query var="query" dataSource="${dbsor}">
SELECT UserId,Email FROM UserDetails
</sql:query>
<c:forEach var="row" items="${query.rows}">
<tr>
<td><cut value="${row.CustId}"/></td>
<td><cut value="${row.Email}"/></td>
</tr>
</c:forEach>

and some codes in SERVLET:
con=pool.getConnection();
request.setAttribute("dbsor",con);
RequestDispatcher view=request.getRequestDispatcher("test.jsp");
view.forward(request, response);

The "pool" is a Connection Pooling Bean.
But it dose not work,log is:
javax.servlet.ServletException: javax.servlet.jsp.JspException: 'dataSource' is neither a String nor a javax.sql.DataSource

DataSource error?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use JSTL instead of scriptlet.This is about JDBC.
 
Similar Threads
Error Handling
Combo box problem in jsp
Problem with Simple JSP page
how add data in database through jsp
howto i use javabean to create table for db's data