Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
William Turner
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
William Turner
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic