Hi Dan,

First you should make sure field != null before trying to put it
in the session. That is what is causing the NullPointerException.

Then add a <pg:param name="fieldname"/> tag inside the <pg:index/>
tag. This will add "fieldname" to the list of parameters that will
be preserved and passed to future pages.

-James

On Mon, Feb 12, 2001 at 09:02:00AM -0800, Dan Lopez wrote:
> I am using pager taglib from www.jsptags.com.  I get
> data from a database fine when I get ALL the data.
>
> However when a user enters info from a form to be used
> in SQL clause, the data comes up on the first page (of
> 1/2/3/4/5... etc) but when you go to the next page,
> the values are null.  Included is some sample code and
> the error 500 that I get.  Please Help!!!!
>
> Thanks
>
> Dan
>
>
> Sample Code============================
>
> <%@ taglib uri="http://someurl.net" prefix="pg" %>
> <%@ page language="java" import="java.sql.*" %>
> <%@ page session= "true" %>
>
>
> <!-- //Prepare session variables with initiall null
> values -->
> <%! String field=""; %>
>
> <% //Get the fields passed from Search request page
> from form submission
>   field = request.getParameter("fieldname");
>   session.putValue("fieldname", field);
>
> %>
>
> <% //Get the fields passed from session values
> String field = (String) session.getValue("fieldname");
> %>
>
> <%
>
>   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
>   Connection myConn =
> DriverManager.getConnection("jdbc:odbc:test_db");
>         Statement stmt = myConn.createStatement();
>         ResultSet myResultSet = stmt.executeQuery("SELECT "
> +field+ " FROM tbl_test");
>
> %>
>
> <%
>         String requestUri = request.getRequestURI();
>         int indexOfqm = requestUri.indexOf('?');
>         if (indexOfqm != -1)
>                 requestUri = requestUri.substring(0, indexOfqm);
>
>         String style = request.getParameter("style");
> %>
> <body bgcolor="#FFFFFF" topmargin="0">
> <pg:pager maxIndexPages="<%= 10 %>" maxPageItems="<%=
> 10 %>">
>   <pg:param name="style"/> <% /* keep track of style
> */ %>
> <table border="0" cellspacing="2" cellpadding="0"
> width="46%" align="center">
> <tr bgcolor="lightgrey">
>     <td width="341" height="7" bgcolor="#663300">
>       <div align="center"><font face="Arial,
> Helvetica, sans-serif" size="2">
>         <b><font color="#FFFFFF">Search
> Results</font></b></font> </div>
>     </tr>
>   <%
>                         if (myResultSet != null) {
>                         while (myResultSet.next()) {
>                         String a = myResultSet.getString(1);
>   %>
>   <pg:item>
>
>   <tr bgcolor="lightgrey">
>     <td width="341" height="8">
>         <div align="left"><font face="Arial, Helvetica,
> sans-serif" size="2"><%= a %>
>         </font> </div>
>   </tr>
>   </pg:item>
>   <%
>         }
>      }
>
>    stmt.close();
>    myConn.close();
> %>
> </table>
>
> <br>
>  <br>
>   <center>
>   <pg:index>
>     <pg:prev>
>     <a href="<%= pageUrl %>">[ (<%= pageNumber %>) <<
> Previous ]</a>
>     </pg:prev>
>     <pg:pages>
>        <a href="<%= pageUrl %>"><%= pageNumber %></a>
>     </pg:pages>
>     <pg:next>
>       <a href="<%= pageUrl %>">[ Next >> (<%=
> pageNumber %>) ]</a>
>     </pg:next>
>   </pg:index>
> </pg:pager>
> </center>
>
> ERROR===========================================
> null
> java.lang.NullPointerException
>         at java.util.Hashtable.put(Unknown Source)
>         at
> allaire.jrun.session.JRunSession.setAttribute(JRunSession.java:240)
>         at
> allaire.jrun.session.JRunSession.putValue(JRunSession.java:226)
>         at
> 
>jrun__test__po_srch_result2ejsp18._jspService(jrun__test__po_srch_result2ejsp18.java:46)
>         at
> allaire.jrun.jsp.HttpJSPServlet.service(HttpJSPServlet.java:40)
>         at
> allaire.jrun.servlet.JRunSE.service(JRunSE.java:1013)
>         at
> allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java:925)
>         at
> allaire.jrun.servlet.JRunNamedDispatcher.forward(JRunNamedDispatcher.java:34)
>         at
> allaire.jrun.jsp.JSPServlet.service(JSPServlet.java:175)
>         at
> allaire.jrun.servlet.JRunSE.service(JRunSE.java:1013)
>         at
> allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java:925)
>         at
> allaire.jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java:88)
>         at
> allaire.jrun.servlet.JRunSE.service(JRunSE.java:1131)
>         at
> allaire.jrun.servlet.JvmContext.dispatch(JvmContext.java:330)
>         at
> allaire.jrun.http.WebEndpoint.run(WebEndpoint.java:107)
>         at allaire.jrun.ThreadPool.run(ThreadPool.java:272)
>         at
> allaire.jrun.WorkerThread.run(WorkerThread.java:75)
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail - only $35
> a year!  http://personal.mail.yahoo.com/
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to