Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > JSP Error | Problem | Question

JSP Error | Problem | Question
Thread Tools
depolitic
Registered User
Join Date: Feb 2003
Status: Offline
Reply With Quote
Jun 16, 2003, 05:16 AM
 
Hi

I am executing a sql query in wich I set maxRows="${noOfRows}" in the sql query. The param value comes from the search page form. It works fine on the first time through. However as soon as I call the next set of results via <a href="maxrows.jsp?start=<c:out value="${param.start + noOfRows}" />">Next Page</a>. The page return s nothing.

The thing is if I the value manualy - <c:set var="noOfRows" value="2" /> - it works fine. Returning 2 results for every page.

Why?? Any help welcome.

------------------
START THE FILE
------------------
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>

<html>
<head>
<title>All Employees</title>
</head>
<body bgcolor="white">

<%-- Set number of rows to process --%>
<c:set var="noOfRows" value="${param.noOfRows}" />

<sql:query var="newsList" startRow="${param.start}" maxRows="${noOfRows}">
SELECT * FROM News
WHERE category LIKE ?
AND title LIKE ?
AND description LIKE ?
AND contributor LIKE ?
ORDER BY title
<sqlaram value ="%${param.category}%" />
<sqlaram value ="%${param.title}%" />
<sqlaram value ="%${param.description}%" />
<sqlaram value ="%${param.contributor}%" />
</sql:query>


<c:choose>
<c:when test="${newsList.rowCount == 0}">
No one seems to work here any more ...
</c:when>
<c:otherwise>
The following people work here:
<p>
<table border="1">
<th>Category</th>
<th>Title</th>
<th>Description</th>
<th>Contributor</th>
<c:forEach items="${newsList.rows}" var="row">
<tr>
<td><c:out value="${row.category}" /></td>
<td><c:out value="${row.title}" /></td>
<td><c:out value="${row.description}" /></td>
<td><c:out value="${row.contributor}" /></td>
</tr>
</c:forEach>
</table>
</c:otherwise>
</c:choose>
<p>
<c:choose>
<c:when test="${param.start > 0}">
<a href="maxrows.jsp?start=<c:out value="${param.start - noOfRows}" />">
Previous Page</a>
</c:when>
<c:otherwise>
Previous Page
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${newsList.limitedByMaxRows}">
<a href="maxrows.jsp?start=<c:out value="${param.start + noOfRows}" />">
Next Page</a>
</c:when>
<c:otherwise>
Next Page
</c:otherwise>
</c:choose>
</body>
</html>
------------------
------------------
     
DaGuy
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jun 17, 2003, 01:17 AM
 
My guess is that when you set the variable manually, it's only scoped for the request. So it vanishes for subsequent requests. Printing the variable before and after the request should help you debug this.

In any event, you need to use a session object, since you are persisting state accross requests.

Hope it helps,

     
depolitic  (op)
Registered User
Join Date: Feb 2003
Status: Offline
Reply With Quote
Jun 18, 2003, 12:43 AM
 
Hi

Setting the scope to session and the param.noOfRows still returned null on later pages. So I just passed the value along with URL in the HREF.

Like this:


<c:when test="${newsList.limitedByMaxRows}">
<a href="maxrows.jsp?start=<c:out value="${param.start + noOfRows}" />&category=<c:out value="${param.category}" />&title=<c:out value="${param.title}" />&description=<c:out value="${param.description}" />&contributor=<c:out value="${param.contributor}" />&noOfRows=<c:out value="${param.noOfRows}" />">Next Page</a>

Is this good practice to do? and why did :

<c:set var="noOfRows" value="${param.noOfRows}" scope="session" />


Not pass the value throught the scope.
     
DaGuy
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jun 18, 2003, 02:52 AM
 
Originally posted by depolitic:
Is this good practice to do?
My humble opinion is no. JSTL is supposed to simplify matters. By encoding the URL in such way, your code ended up more complex than what you would've gotten by using straight forward Java in your JSP. This defeats the need for JSTL.

Originally posted by depolitic:

why did :

<c:set var="noOfRows" value="${param.noOfRows}" scope="session" />

Not pass the value throught the scope.
Hard to say... In any event, the scope is not something you pass values through. It's just a flag that tells the container to maintain an implicit object called "session" (for this case).

My suggestion is to chew and digest some material about session management but without the JSTL tags. Take a look at:

http://www.jspinsider.com/reference/...html#functions

If you are hell bent for JSTL then take a look at:

http://javaalmanac.com/egs/javax.ser...ttr.html?l=rel

Best,
( Last edited by DaGuy; Jun 18, 2003 at 03:04 AM. )
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:48 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,