Using Collections within JSP and beans

Hi I have a bean setup that contains a collection (linkedList of objects)
A servlet sets up all the information and forwards to a jsp page
ResourceInformation resourceInfo = new ResourceInformation();
         resourceInfo.setResourceList(list);
         request.setAttribute("resourceInformation",resourceInfo);
         RequestDispatcher dispatcher = request.getRequestDispatcher(address);
         dispatcher.forward(request,response);My question is what is the prefered way of iterating through this collection from the jsp page
as I havent been able to find any examples of JSP pages utilising collections
Thanks a lot

The JSTL (http://java.sun.com/products/jsp/jstl/) contains a <c:forEach> tag you can use to iterate collections - e.g:
<c:forEach var="resource" items="${requestScope.resourceInformation.resourceList}">
  <tr>
    <td>${resource.name}</td>
  </tr>
</c:forEach>

Similar Messages

  • Please recommend IDE for JSP and Beans

    Hi guys,
    I am looking for a decent IDE to work with JSP and Beans. I have tried JBuilder which has too much going on at the same time and I find it to be an overkill for what I am doing; I find NetBeans kind of irritating. I develop web applications, hence I dont need any GUI stuff for beans.
    Just looking for something that will enable me to rapidly develop beans as a support system for JSP pages and at the same time, it should provide good support for coding JSP pages. Little bit of management functions wont hurt either, but are not required. I dont mind if I have to pay for the IDE. Any recommendations?

    I like Eclipse for Java Development, and I use the MyEclipse plug-in for J2EE development.
    There is a free J2EE plug-in (Lomboz) but I'd much rather pay the $29.99/year for MyEclipse. It's been perfect for me.

  • How to list an array of objects using struts in jsp and ActionForm

    I am using the struts ActionForm and need to know how to display an Array of objects. I am assuming it would look like this in the ActionForm:
    private AddRmvParts addRmv[];
    But I am not sure how the getter and setter in the ActionForm should look. Should it be a Collection or an Iterator?
    I am thinking I need to use an iterator in the jsp page to display it.
    I am also wondering if the AddRmvParts class I have can be the same class that gets populated by the retrieval of data from the database. This class has 10 fields that need to display on the jsp page in 1 row and then multiple rows of these 10 fields.
    Thanks.

    Most probably the easiest way to make it accessible in your page is as a collection.
    ie
    public Collection getAddRmvParts()
    You can use the <logic:iterate> or a <c:forEach>(JSTL) tag to loop through the collection
    As long as the individual items in the collection provide get/set methods you can access them with the dot syntax:
    Example using JSTL:
    <c:forEach var="addRmvPart" items="${addRmvParts}">
      <c:out value="${addRmvPart.id} ${addRmvPart.name} ${addRmvPart.description}"/>
    </c:forEach>

  • Help on JSP and Beans!

    Hi! I am new to JSP and I need help on how to utilize java bean on JSP. I have gone through this forum, I found similar question but did not find any answer that could solve my question. Tons of thanks to anyone who could help me out!
    I have a java bean class called Bean1, which I put under /ROOT/WEB-INF/classes/, and a JSP file that utilizes class Bean1, saved under /ROOT/, which should be a correct way indicated by several posts I found in this forum. But when I try to compile the JSP file over TOMCAT4.1 over http://localhost:8080/beanexample1.jsp, it throws me a lot of error messages (see below). I've been struggling for so long. Any help is greatly apprecitated! Thanks!
    Bo
    The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 0 in the jsp file: /beanexample1.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\beanexample1_jsp.java:41: cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    Bean1 bean1 = null;
    ^
    An error occurred at line: 0 in the jsp file: /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\beanexample1_jsp.java:43: cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    bean1 = (Bean1) pageContext.getAttribute("bean1", PageContext.PAGE_SCOPE);
    ^
    An error occurred at line: 0 in the jsp file: /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\beanexample1_jsp.java:46: cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    bean1 = (Bean1) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "Bean1");
    ^
    An error occurred at line: 13 in the jsp file: /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\beanexample1_jsp.java:66: cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    out.print(JspRuntimeLibrary.toString((((Bean1)pageContext.findAttribute("bean1")).getName())));
    ^
    An error occurred at line: 16 in the jsp file: /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\beanexample1_jsp.java:69: cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    out.print(JspRuntimeLibrary.toString((((Bean1)pageContext.findAttribute("bean1")).getSeventhPrimeNumber())));
    ^
    An error occurred at line: 19 in the jsp file: /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\beanexample1_jsp.java:72: cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    out.print(JspRuntimeLibrary.toString((((Bean1)pageContext.findAttribute("bean1")).getCurrentTime())));
    ^
    An error occurred at line: 27 in the jsp file: /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\beanexample1_jsp.java:79: cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    out.print(JspRuntimeLibrary.toString((((Bean1)pageContext.findAttribute("bean1")).getColor())));
    ^
    7 errors
         at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
         at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
         at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:340)
         at org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
         at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
         at java.lang.Thread.run(Thread.java:484)

    you need to put your bean in a package. do this by
    making a sub directory under the classes directory,
    let's say you call it "mybeans".
    so copy Bean1.java to
    /ROOT/WEB-INF/classes/Bean1.java
    add the line "package mybeans;"
    to the top of the Bean1.java file,
    and then compile it there.
    the standard way to use the bean in your jsp file is like this:
    <jsp:useBean id="thisbean" scope="page" class="mybeans.Bean1" />
    this <jsp:usebean> tag instantiates the bean for you.
    then refer to it by its id:
    thisbean.myMethod();
    thisbean.setProperty();
    I have a java bean class called Bean1, which I put
    under /ROOT/WEB-INF/classes/, and a JSP file that
    utilizes class Bean1, saved under /ROOT/, which should
    be a correct way indicated by several posts I found in
    this forum. But when I try to compile the JSP file
    over TOMCAT4.1 over
    http://localhost:8080/beanexample1.jsp, it throws me a
    lot of error messages (see below). I've been
    struggling for so long. Any help is greatly
    apprecitated! Thanks!
    Bo
    The server encountered an internal error () that
    prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile
    class for JSP
    An error occurred at line: 0 in the jsp file:
    /beanexample1.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    C:\Program Files\Apache Group\Tomcat
    4.1\work\Standalone\localhost\_\beanexample1_jsp.java:4
    : cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    Bean1 bean1 = null;
    ^
    An error occurred at line: 0 in the jsp file:
    /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat
    4.1\work\Standalone\localhost\_\beanexample1_jsp.java:4
    : cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    bean1 = (Bean1)
    (Bean1) pageContext.getAttribute("bean1",
    PageContext.PAGE_SCOPE);
    ^
    An error occurred at line: 0 in the jsp file:
    /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat
    4.1\work\Standalone\localhost\_\beanexample1_jsp.java:4
    : cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    bean1 = (Bean1)
    1 = (Bean1)
    java.beans.Beans.instantiate(this.getClass().getClassLo
    der(), "Bean1");
    ^
    An error occurred at line: 13 in the jsp file:
    /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat
    4.1\work\Standalone\localhost\_\beanexample1_jsp.java:6
    : cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    out.print(JspRuntimeLibrary.toString((((Bean1)pageCont
    xt.findAttribute("bean1")).getName())));
    ^
    An error occurred at line: 16 in the jsp file:
    /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat
    4.1\work\Standalone\localhost\_\beanexample1_jsp.java:6
    : cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    out.print(JspRuntimeLibrary.toString((((Bean1)pageCont
    xt.findAttribute("bean1")).getSeventhPrimeNumber())));
    ^
    An error occurred at line: 19 in the jsp file:
    /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat
    4.1\work\Standalone\localhost\_\beanexample1_jsp.java:7
    : cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    out.print(JspRuntimeLibrary.toString((((Bean1)pageCont
    xt.findAttribute("bean1")).getCurrentTime())));
    ^
    An error occurred at line: 27 in the jsp file:
    /beanexample1.jsp
    Generated servlet error:
    C:\Program Files\Apache Group\Tomcat
    4.1\work\Standalone\localhost\_\beanexample1_jsp.java:7
    : cannot resolve symbol
    symbol : class Bean1
    location: class org.apache.jsp.beanexample1_jsp
    out.print(JspRuntimeLibrary.toString((((Bean1)pageCont
    xt.findAttribute("bean1")).getColor())));
    ^
    7 errors
    at
    org.apache.jasper.compiler.DefaultErrorHandler.javacEr
    or(DefaultErrorHandler.java:130)
    at
    org.apache.jasper.compiler.ErrorDispatcher.javacError(
    rrorDispatcher.java:293)
    at
    org.apache.jasper.compiler.Compiler.generateClass(Comp
    ler.java:340)
    at
    org.apache.jasper.compiler.Compiler.compile(Compiler.j
    va:352)
    at
    org.apache.jasper.JspCompilationContext.compile(JspCom
    ilationContext.java:474)
    at
    org.apache.jasper.servlet.JspServletWrapper.service(Js
    ServletWrapper.java:184)
    at
    org.apache.jasper.servlet.JspServlet.serviceJspFile(Js
    Servlet.java:295)
    at
    org.apache.jasper.servlet.JspServlet.service(JspServle
    .java:241)
    at
    javax.servlet.http.HttpServlet.service(HttpServlet.jav
    :853)
    at
    org.apache.catalina.core.ApplicationFilterChain.intern
    lDoFilter(ApplicationFilterChain.java:247)
    at
    org.apache.catalina.core.ApplicationFilterChain.doFilt
    r(ApplicationFilterChain.java:193)
    at
    org.apache.catalina.core.StandardWrapperValve.invoke(S
    andardWrapperValve.java:260)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipe
    ineValveContext.invokeNext(StandardPipeline.java:643)
    at
    org.apache.catalina.core.StandardPipeline.invoke(Stand
    rdPipeline.java:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(Containe
    Base.java:995)
    at
    org.apache.catalina.core.StandardContextValve.invoke(S
    andardContextValve.java:191)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipe
    ineValveContext.invokeNext(StandardPipeline.java:643)
    at
    org.apache.catalina.core.StandardPipeline.invoke(Stand
    rdPipeline.java:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(Containe
    Base.java:995)
    at
    org.apache.catalina.core.StandardContext.invoke(Standa
    dContext.java:2415)
    at
    org.apache.catalina.core.StandardHostValve.invoke(Stan
    ardHostValve.java:180)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipe
    ineValveContext.invokeNext(StandardPipeline.java:643)
    at
    org.apache.catalina.valves.ErrorDispatcherValve.invoke
    ErrorDispatcherValve.java:170)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipe
    ineValveContext.invokeNext(StandardPipeline.java:641)
    at
    org.apache.catalina.valves.ErrorReportValve.invoke(Err
    rReportValve.java:172)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipe
    ineValveContext.invokeNext(StandardPipeline.java:641)
    at
    org.apache.catalina.core.StandardPipeline.invoke(Stand
    rdPipeline.java:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(Containe
    Base.java:995)
    at
    org.apache.catalina.core.StandardEngineValve.invoke(St
    ndardEngineValve.java:174)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipe
    ineValveContext.invokeNext(StandardPipeline.java:643)
    at
    org.apache.catalina.core.StandardPipeline.invoke(Stand
    rdPipeline.java:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(Containe
    Base.java:995)
    at
    org.apache.coyote.tomcat4.CoyoteAdapter.service(Coyote
    dapter.java:223)
    at
    org.apache.coyote.http11.Http11Processor.process(Http1
    Processor.java:432)
    at
    org.apache.coyote.http11.Http11Protocol$Http11Connecti
    nHandler.processConnection(Http11Protocol.java:386)
    at
    org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolT
    pEndpoint.java:534)
    at
    org.apache.tomcat.util.threads.ThreadPool$ControlRunna
    le.run(ThreadPool.java:530)
         at java.lang.Thread.run(Thread.java:484)

  • JSP AND BEAN PROBLEm   java.lang.nullpointerexception   help me please

    hello i have a problem, when i open login.jsp and enter the form i have nullpointerexception. i don't understand where i wrong... i use tomcat 5.5 ... sorry for my english i'm italian and i speak only italian :(
    login.jsp this is the code of the java server page
    <html>
    <%@ page language="java" import="java.sql.*" %>
    <jsp:useBean id="lavoro" scope="page" class="Ok.Dino"/>
    <%@ page session="false" %>
    <style type="text/css">
    <!--
    body {
         background-color: #003366;
    a:link {
         color: #CCCCCC;
    .style1 {
         color: #000000;
         font-weight: bold;
         font-size: x-large;
    .style4 {font-size: 18px}
    -->
    </style>
    <body>
    <%if(request.getMethod()=="GET"){
    %>
    <form action="login.jsp" method= "POST" name="frmlogin" id="frmlogin">
         <div align="center">
           <p class="style1">AUTENTICAZIONE</p>
           <p> </p>
           <table width="318" height="140" border="1">
            <tr>
              <td width="95" height="60" bordercolor="#000000" bgcolor="#0066CC"><p align="center"><strong>USER</strong></p>          </td>
              <td width="207" bgcolor="#0099CC"><p align="center">
                <input type="text" name="txtnome"></p>
              </td>
            </tr>
            <tr>
              <td height="72" bordercolor="#000000" bgcolor="#0066CC"><strong>PASSWORD</strong> </td>
              <td width="207" bgcolor="#0099CC"><div align="center">
                <input name="pwdtxt" type="password">
              </div></td>
            </tr>
          </table>
           <table width="318" border="1">
            <tr>
              <td width="318" height="87"> <div align="center">
                <input name="submit" type="submit" value="invia"  >
              </div>
              <p align="center"><strong><span class="style4">Se non sei registrato fallo <a href="file:///C|/Documents and Settings/access/Documenti/My Received Files/registrazione.jsp">adesso </a></span></strong></p></td>
            </tr>
          </table>
           <p> </p>
           <p> </p>
      </div>
    </form>
    <%}else {  %>
    <%lavoro.settxtnome(request.getParameter("txtnome"));%>
    <%!ResultSet rs=null;
         String x=null;
    %>
    <% lavoro.cn_db("dbutenti");%>
    <% rs=lavoro.run_query("SELECT user FROM utenti");%>
    <%}%>
    </body>
    </html>and this is the bean code
    package Ok;
    import java.sql.*;
    public class Dino
    private String txtnome,pwdtxt;
    private Connection cn=null;
    private Statement st=null;
    private ResultSet Rs=null;
    public String gettxtnome()
    return txtnome;
    public String getpwdtxt()
    return pwdtxt;
    public void settxtnome(String n)
    this.txtnome=n;
    public void setpwdtxt(String n)
    this.pwdtxt=n;
    public void cn_db(String db)
              if(cn==null){
              //1. Caricamento del driver
              try{
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              }catch(ClassNotFoundException cnfe){
                   System.out.println("impossibile caricare il driver");
                   System.exit(1);
              try{
                   //2. Connessione al DB
                   cn = DriverManager.getConnection("jdbc:odbc:"+db);
                   //3. creazione degli oggetti Statement e ResultSet
                   st =cn.createStatement();
              }catch(SQLException e){
                   System.out.println(e+"jjj");
    }else{
         System.out.print("errore database gi�� creato");
    public ResultSet run_query(String qr)
         try{
    Rs=st.executeQuery(qr);
         }catch(SQLException e)
         System.out.print(e+"ecco l'error");
         return Rs;
    }

    Do you understand when a NullPointerException will be thrown? This will be thrown if you want to access an uninstantiated Object.
    So look to the stacktrace and go to the line where the NPE is been thrown and doublecheck if the object reference is actually instantiated.
    Or add a null-check to the object reference:if (someObject != null) {
        someObject.doSomething();
    }or just instantiate it:if (someObject == null) {
        someObject = new SomeObject();
    someObject.doSomething();

  • Where do I place JSP and Beans?

    Hello,
    I have just installed JDeveloper and have no idea where to place JSP pages and Bean class files so thet JDeveloper can access them when I run or debug a page.
    Any help would be appreciated.

    In JDeveloper, applications are grouped by one or more projects and a workspace containing projects. In your case, if you already have beans and JSPs built, here's what you need to do:
    1. Create a new workspace.
    2. Create a project using the 'create a project from existing source code' option.
    3. Optionally check the 'copy to project's source directory' to include your files in the project.
    Hope this helps,
    Lynn
    Java Tools Team

  • How to done Next and Previous operations using(struts or jsp and servlets).

    I have some problem with Next and Previous Operations in my application. I solve that problem by my own. But I need some more information to solve that problem.
    In order to solve this problem, 1st i moved all the Dara Base records into one collection.And I set that collection Object in Session scope in Servlet file.And i dispatch the request to one jsp(Show.jsp) . The code of that is given bellow.
    <%@page language="java"%>
    <%@page import="java.util.*"%>
    <%@page import="home.servlet.beans.*"%>
    <%!
         public static int no=0;
    %>
    <html>
         <body>          
                   <%
                        String s=request.getParameter("nam");
                        if(s==null)
                             s="some";
                        ArrayList a=(ArrayList)session.getAttribute("tv");
                        if(!s.equals("pre"))
                             int i=no;
                             %>
                             <table border=1>
                   <tr>
                        <th>DEPTNO</th>
                        <th>DNAME</th>
                        <th>LOC</th>
                   </tr>
                   <%
                        if((no+1)<a.size())
                        for(i=no;i<(no+2);i++)
                             SelectBean sb=(SelectBean)a.get(i);
                             %>
                             <tr>
                                  <td><%=sb.getDeptno()%></td>
                                  <td><%=sb.getDname()%></td>
                                  <td><%=sb.getLoc()%></td>
                             </tr>
                             <%
                             no=no+2;
                        else
                             if(i<a.size())
                             for(i=no;i<a.size();i++)
                             SelectBean sb=(SelectBean)a.get(i);
                             %>
                             <tr>
                                  <td><%=sb.getDeptno()%></td>
                                  <td><%=sb.getDname()%></td>
                                  <td><%=sb.getLoc()%></td>
                             </tr>
                             <%
                             else
                                  out.println("<tr><td colspan='3'>There is no records to display</td></tr>");
                        else
                             %>
                             <table border=1>
                   <tr>
                        <th>DEPTNO</th>
                        <th>DNAME</th>
                        <th>LOC</th>
                   </tr>
                   <%
                             if(no==a.size())
                                  no=no-1;
                             int i=no;
                             for(i=no;i>(no-2);i--)
                                  if(i==-1)
                                       break;
                                  SelectBean sb=(SelectBean)a.get(i);
                             %>
                             <tr>
                                  <td><%=sb.getDeptno()%></td>
                                  <td><%=sb.getDname()%></td>
                                  <td><%=sb.getLoc()%></td>
                             </tr>
                             <%                               
                             no=no-2;
                             if(no<0)
                                  no=0;
                   %>
                   </table>
                   <br>
                   next
                   previous
         </body>
    </html>
    If u have any other idea please reply to me. Please copy the above code and work with your application.

    It's a classic paging feature.
    And since it's a classic feature, you have most of the work already done for you, like JSP paging tags.
    You just need to Google for "jsp tag paging" or something to that effect to get several useful links.

  • Memory leak with jsp and beans

    The application we have created has one particular page that is designed to stay up in the browser and refresh with new information from database queries once every 60 seconds. Running with Tomcat3.2.1 and IE5.5
    The problem is that the memory usage of java.exe continues to grow until the machine crashes from out of memory. It does take more than 24 hours to crash.
    Things I have tried to do to track down the problem or eliminate the problem.
    - I have explicitly set the scope of the beans to "page"
    - I have watched the DatabaseAccess.class (the beans are all extended from this class) and put in code to watch how many instantiations of the class are made and subsequently garbage collected. This appears to be where the memory leak may reside - hundreds of instantiations from some other source than the page I am displaying.
    - the top frame makes database queries for security and display of a menu system dependant upon security clearance. It does not set any time for refresh (refresh == 0). Nor does it explicitly set a scope for the beans.
    - I have run a different jsp engine to see if this was directly related to Tomcat - same problem with resin2.0.0
    The main jsp page that is in the bottom section of the page has the following code:
    ** only the relevant lines are included here
    <%@ include file="../../common.jsp" %>
    <%
         refresh=60;
    %>
    <head>
    <%@ include file="../../meta_head.jsp" %>
    </head>
    <body bgcolor="#FFFFFF" text="#003399" link="#660099" vlink="#990099" alink="#006666" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <%@ include file="../../access.jsp" %>
    <%@ include file="../../page_title.jsp" %>
    <jsp:useBean id="Line" class="jsp.Line" scope="page" />
    <jsp:useBean id="Machine" class="jsp.Machine" scope="page"/>
    <jsp:useBean id="Alarm_log" class="jsp.Alarm_log" scope="page"/>
    contents of meta_head.jsp
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <META HTTP-EQUIV= "expires" content = "0">
    <META HTTP-EQUIV="Pragma" CONTENT="no_cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache" forua="true">
    <META NAME="robots" content="NOINDEX,NOFOLLOW">
    <%
    if (refresh > 0)
    %>
    <meta http-equiv="Refresh" content="<%= refresh %>">
    <%
    If anyone has some suggestions on how to trap this memory leak, it would be terrific. Or, some other things to try to stop the instantiation of the DatabaseAccess object (perhaps setting the scope of the beans in the header to "session" or "application"?).
    Thanks in advance.
    Roberta

    jsp:useBean tags scope declaration :
    page = Create a new instance on each load.
    session = Load instance from the session, if not there, create one
    application = Load instance from the ServletContext, if not there, create one.
    Not sure how you are populating the data variables, but make sure you are closing all ResultSet, (Prepared)Statement, and Connection objects.

  • JSP and Bean

    Hi!
    I am trying to write a simple code using bean and JSP.
    I have 3 pages:
    GetName.html (This is a html form which calls SaveName.jsp)
    <HTML>
    <BODY>
    <FORM METHOD=POST ACTION="SaveName.jsp">
    What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
    What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
    What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4>
    <P><INPUT TYPE=SUBMIT>
    </FORM>
    </BODY>
    </HTML>
    SaveName.jsp (In this i am using a bean to store the field data)
    <jsp:useBean id="user" class="UserData" scope="session">
    </jsp:useBean>
    <jsp:setProperty name="user" property="*"/>
    <HTML>
    <BODY>
         Continue
    </BODY>
    </HTML>
    UserData.java
    public class UserData {
    String username;
    String email;
    int age;
         public UserData()
    public void setUsername( String value )
    username = value;
    public void setEmail( String value )
    email = value;
    public void setAge( int value )
    age = value;
    public String getUsername() { return username; }
    public String getEmail() { return email; }
    public int getAge() { return age; }
    I am using a WebLogic Server 6.1. I kept the UserData class file under the WEB_INF\Classes folder.
    I am getting an error as "cannot resolve the symbol" in line 1 of SaveName.jsp
    I would appreciate if you somebody could give a thought.
    Awaiting reply.

    Hi,
    You have put the Bean UserData in the directory WEB_INF\classes but in your code you are not specifing to that directory. Here is the correct code.
    jsp:useBean id="user" class="classes.UserData" scope="session">

  • JSP and beans

    Is the bean spec for use w/ jsp any different than the one for J2EE? are there any required methods for use w/ jsp like in tag handlers?
    Thanks

    just make sure that you meet the basics of the bean properties for example
    your bean class should meet the following constraints
    no argument constructer
    if you have instance variables i.e count
    make sure that you have public getter and setters for it
    getCount()
    setCount(int c)
    you may add as much methods as you want
    make sure that your bean is existing either under web-inf/classes
    or web-inf/lib
    regards

  • Handling Session in jsp and bean scope

    i have problems with handling session in jsp
    I want to check on all jsp pages
    first thing is session is null
    i want to him to be redirected to first page
    and he should not be able to go ahead
    I tried
    if(session ==null)
    response.sendRedirect("Login.jsp");
    but this does not seem to work
    It is very crtical problem can any one answer
    this asap
    Also i wanted to know that
    I have bean which in turn calls static methods of another class which holds all DomainTable(database tables which do not change frequently)
    Information .
    This is bean is being implemented by me
    in seession scope in a jsp
    Do u guys think it would be goo idea to change
    scop of this bean as Application in jsp
    if so what would be advantages for same
    I would appericate if i could a quick reply on both
    question
    as i am time crunch
    arsh

    You will always get some value of session and your code wont work. At the end of your Login.jsp, you should create a sesssion and store attributes. Check for these attributes in session, rather than checking session==null.

  • Passing values between JSP and Bean

    I am trying to validate a date entered by the user on a form. I need to do an "alert" when the user enters a date outside of the valid range depending on a value entered in a drop down.
    Am doing this in checkform function. Here is what I want to do:
    1. Send the the value from the drop down and the date to bean to do the calculations. Call the EJB function from checkform.
    2. Get a string values back into the jsp from the bean
    3. Blow an error to the user to enter a valid date.
    Any help in this case would be greatly appreciated.
    Thanks.

    I only see some design requirements.
    What's the exact coding question? Where are you stucking while coding those requirements accordingly?

  • Single database connection create and using  all programs jsp and servlet

    Hai
    i am create databaset connection using that all programs how to implement

    Post the steps you managed already. If you don't know anything about how to receive data from a database try this link:
    http://java.sun.com/docs/books/tutorial/jdbc/index.html

  • How can I connect to the database using ODBC within excel.

    Hi,
    How can I connect to the database using ODBC within excel and just refresh the data when needed.
    Thanks,
    Priyanka
    Edited by: user554934 on Jun 9, 2009 2:53 AM

    This is NOT an APEX relevant question, try posting it in the SQL/PL/SQL Forum..
    Thank you,
    Tony Miller
    Webster, TX

  • JSP Accesing Bean Problem

    I need a help in this jsp and bean Please provide the solution
              This is the bean
              import java.text.*;
              import java.util.*;
              import java.io.Serializable;
              public class DateBean implements Serializable {
              public DateBean() {}
              SimpleDateFormat sdf;
              public void setFormat(String format) {
              sdf = new SimpleDateFormat(format);
              public String getCurrentTime() {
              return sdf.format(new Date());
              This is the date.jsp
              <html>
              <head>
              <title>A JSP that sets a property</title>
              </head>
              <body>
              The current time and date, in several formats, courtesy
              a bean:<p>
              <!-- begin example -->
              <jsp:useBean
              id="date"
              class="DateBean"/>
              <ul>
              <jsp:setProperty name="date" property="format"
              value="EEEE, MMMM dd yyyy 'at' hh:mm"/>
              <li><jsp:getProperty name="date" property="currentTime"/>
              <jsp:setProperty name="date" property="format"
              value="hh:mm:ss MM/dd/yy"/>
              <li><jsp:getProperty name="date" property="currentTime"/>
              <jsp:setProperty name="date" property="format"
              value="yyyyy.MMMMM.dd GGG hh:mm aaa"/>
              <li><jsp:getProperty name="date" property="currentTime"/>
              </ul>
              <!-- end example -->
              </body>
              </html>
              AND THIS is the compilation error
              Error: [jspc]: 1 file(s) failed:
              /dates.jsp
              [Compilation errors : ]
              E:\DateBean\__dates.java:134: cannot resolve symbol
              symbol : class DateBean
              location: class jsp_servlet.__dates
              DateBean date = null; //[ /dates.jsp; Line: 13]
              ^
              E:\DateBean\__dates.java:135: cannot resolve symbol
              symbol : class DateBean
              location: class jsp_servlet.__dates
              date = (DateBean)pageContext.getAttribute("date"); //[ /dates.jsp; Line: 13]
              ^
              E:\DateBean\__dates.java:138: cannot resolve symbol
              symbol : class DateBean
              location: class jsp_servlet.__dates
              date = (DateBean)pageContext.getAttribute("date"); //[ /dates.jsp; Line: 13]
              ^
              E:\DateBean\__dates.java:140: cannot resolve symbol
              symbol : class DateBean
              location: class jsp_servlet.__dates
              date = new DateBean(); //[ /dates.jsp; Line: 13]
              ^
              4 errors
                   at weblogic.jspc.doCompile(Ljava.lang.String;Ljava.util.List;Lweblogic.utils.Getopt2;ZLjava.lang.String;)V(jspc.java:839)
                   at weblogic.jspc.runJspc(Lweblogic.utils.classloaders.GenericClassLoader;Ljava.io.File;Ljava.util.Map;Z)V(jspc.java:632)
                   at weblogic.jspc.runBodyInternal()V(jspc.java:410)
                   at weblogic.jspc.runBody()V(jspc.java:319)
                   at weblogic.utils.compiler.Tool.run([Ljava.lang.String;)V(Tool.java:146)
                   at weblogic.utils.compiler.Tool.run()V(Tool.java:103)
                   at weblogic.jspc.main([Ljava.lang.String;)V(jspc.java:708)
              java.lang.Exception: [Compilation errors : ]
              E:\DateBean\__dates.java:134: cannot resolve symbol
              symbol : class DateBean
              location: class jsp_servlet.__dates
              DateBean date = null; //[ /dates.jsp; Line: 13]
              ^
              E:\DateBean\__dates.java:135: cannot resolve symbol
              symbol : class DateBean
              location: class jsp_servlet.__dates
              date = (DateBean)pageContext.getAttribute("date"); //[ /dates.jsp; Line: 13]
              ^
              E:\DateBean\__dates.java:138: cannot resolve symbol
              symbol : class DateBean
              location: class jsp_servlet.__dates
              date = (DateBean)pageContext.getAttribute("date"); //[ /dates.jsp; Line: 13]
              ^
              E:\DateBean\__dates.java:140: cannot resolve symbol
              symbol : class DateBean
              location: class jsp_servlet.__dates
              date = new DateBean(); //[ /dates.jsp; Line: 13]
              ^
              4 errors
                   at weblogic.jspc.doCompile(Ljava.lang.String;Ljava.util.List;Lweblogic.utils.Getopt2;ZLjava.lang.String;)V(jspc.java:842)
                   at weblogic.jspc.runJspc(Lweblogic.utils.classloaders.GenericClassLoader;Ljava.io.File;Ljava.util.Map;Z)V(jspc.java:632)
                   at weblogic.jspc.runBodyInternal()V(jspc.java:410)
                   at weblogic.jspc.runBody()V(jspc.java:319)
                   at weblogic.utils.compiler.Tool.run([Ljava.lang.String;)V(Tool.java:146)
                   at weblogic.utils.compiler.Tool.run()V(Tool.java:103)
                   at weblogic.jspc.main([Ljava.lang.String;)V(jspc.java:708)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I just wanted to say THANK YOU! This stuff can be a real pain when all the documentation shows everything should be working but it doesn't.
    I will pass on this little piece of info to the next confused person.
    shoot me an e-mail sometime [email protected]

Maybe you are looking for

  • Patch 9655006 failed with code 135 when applying to Oracle Restart

    Hi all, I install Oracle RAC single node version 11.2.0.1 on Linux (kernel 2.6.18). I try to apply patch 9655006 (prerequis for upgrade to 11.2.0.2). Everything is OK for grid applying with success. When I apply this patch to oracle db home, I get :

  • Annoying window switch in Mail Using Safari's "Mail Link to This Page..."

    Anyone else have the annoying problem where they use Safari's "Mail Link to This Page", and it opens a New Mail Composer Window, but then opens Mail's main window right over it, forcing you to switch back to the Composer window? Only seems to happen

  • Need  NetWeaver XI Documents  (Step by step Procedure)

    Hi ALL, I  Got the chance to work in XI but i do not have any documents  on XI  , and please guide me how to handle  the XI application ... Any one has step by step procedures mail me <b>[email protected]</b> Please help me ... Regards Puru

  • What is are 'Tasks'

    Documentation issue: When one asks for the API for highlighted text one is presented its documentation and the first thing one sees in the table of contents is "Tasks". I understand class methods, and instance methods but what is meant by "Tasks"? A

  • Trouble launching mocha

    everytime i try to track using Mocha in my AE6, it comes up with this error message.. License Error: mocha AE CS6 must only be launched from After Effects Please visit our FAQ at http://www.imagineersystems.com/support/faq for further information. an