Results 1 to 9 of 9

Thread: List + JSTL

  1. #1
    initmax's Avatar
    initmax is offline Member
    Join Date
    Oct 2009
    Posts
    9
    Rep Power
    0

    Default List + JSTL

    Hello all, how can print array object "List" in JSTL?

    class MySQLQyery:

    PHP Code:
    package MySQL;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    import java.util.*;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    /**
     *
     * @author initmax
     */
    public class MySQLQuery {
    
        private Connection CurrentConnect; //obj for connect to databae
      
    
    public MySQLQuery() {}
    
    //constructor accept current conection database
    public MySQLQuery(Connection CurrentConnectBase) {
        CurrentConnect = CurrentConnectBase;
    }
    
    //*****************************************************************
    //method accept name table and link on List, after work return all info on this table inside List
    public List<GenPageMySQL> selectAllField(String NameTable, List<GenPageMySQL> ListPageObj) {
           try {
             Statement st = CurrentConnect.createStatement();
             String query = ("select * from "+NameTable);
             ResultSet resultQuery = null;
             resultQuery = st.executeQuery(query);
    
    
    //step in cycle after execution query, and create Vector object
               while (resultQuery.next()) {
                  GenPageMySQL PageObj = new GenPageMySQL();
    
                  PageObj.setId(resultQuery.getInt("id"));
                  PageObj.setTheme(resultQuery.getString("theme"));
                  PageObj.setPage(resultQuery.getString("page"));
    
                  ListPageObj.add(PageObj); //add obj in tail vector
               }
    
    
           }
           catch (SQLException e) {
             e.printStackTrace();
          }
    
           return ListPageObj;
             
    }
    
    
        /**
        *@set the CurrentConnect
        */
        public void setConnection(Connection CurrentConnectBase) {
             CurrentConnect = CurrentConnectBase;
        }
    
    
    }

    PHP Code:
    import java.util.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import MySQL.*;
    
    public class indexServlet extends HttpServlet {
    
        private  String getpage;
        //Connected MySQL
        private MySQLConnect MySQLConnectObj = new MySQLConnect();
        private MySQLQuery MySQLQueryObj = new MySQLQuery();
    
        public void init(){
              MySQLConnectObj.downloadDriver();
              MySQLConnectObj.connected();
              
              //Use current connection, for execution query
              MySQLQueryObj.setConnection(MySQLConnectObj.getConnection());
        }
     
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException, NullPointerException  {
      //      init();
            
    
            PrintWriter out = response.getWriter();
    
    //GET case useer
          getpage = request.getParameter("page");
    
    
          out.print("MySQLConnectObj.GetConnection() = "+MySQLConnectObj.getConnection());
    
    //Check curent connect to database
          if(MySQLConnectObj.getConnection() != null)  {
              
                      
    
                List<GenPageMySQL> ListPageObj = new ArrayList();
                //get List<RowObject>
                ListPageObj = MySQLQueryObj.selectAllField("up_menu",ListPageObj);
      
    
                out.print("Size Page objects = "+ListPageObj.size());
    
                request.setAttribute("upMenu",ListPageObj);
                RequestDispatcher Dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/jsp/index.jsp");
                Dispatcher.forward(request, response);
          }
    
    
          else if(MySQLConnectObj.getConnection() == null){
                init() ;
          }
    
    
            out.print("MySQLConnectObj.GetConnection() = "+MySQLConnectObj.getConnection());
    
             MySQLConnectObj.disConnected();
         }
    
    }
    string   {code}out.print("Size Page objects = "+ListPageObj.size()); {code} == worked,  I get count objects correct

    How I can output fields Object GenPageMySQL in JSTL?

    writing so:
    PHP Code:
             <c:out value="hello, Max" />
             <c:out value="${10+20/2}" />
    
             <c:forEach items="${upMenu}" var="Object" >      
                     
                   <c:out value="${Object.getId}"> </c:out>
        
             </c:forEach>
    
        </body>
    </html>
    but get error:

    PHP Code:
    HTTP Status 500 - 
    
    type Exception report
    
    message 
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception 
    org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/index.jsp at line 36
    
    33:          <c:forEach items="${upMenu}" var="Object" >
    34:          
    35:                  
    36:                <c:out value="${Object.getId}"> </c:out>
    37: 
    38:     
    39:          </c:forEach>
    
    
    Stacktrace:
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	indexServlet.doGet(indexServlet.java:49)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    
    
    root cause 
    javax.el.PropertyNotFoundException: Property 'getId' not found on type MySQL.GenPageMySQL
    	javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:193)
    	javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:170)
    	javax.el.BeanELResolver.property(BeanELResolver.java:279)
    	javax.el.BeanELResolver.getValue(BeanELResolver.java:60)
    	javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
    	org.apache.el.parser.AstValue.getValue(AstValue.java:118)
    	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    	org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
    	org.apache.jsp.WEB_002dINF.jsp.index_jsp._jspx_meth_c_005fout_005f2(index_jsp.java:209)
    	org.apache.jsp.WEB_002dINF.jsp.index_jsp._jspx_meth_c_005fforEach_005f0(index_jsp.java:175)
    	org.apache.jsp.WEB_002dINF.jsp.index_jsp._jspService(index_jsp.java:98)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	indexServlet.doGet(indexServlet.java:49)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    
    
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
    How I can in output print fields my Object?
    Last edited by initmax; 11-04-2009 at 09:13 PM.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    1.) Please use code tags when posting code and make sure its formatted.
    2.) What is upMenu?
    3.) What exception is reported as the cause of the JspException?

  3. #3
    initmax's Avatar
    initmax is offline Member
    Join Date
    Oct 2009
    Posts
    9
    Rep Power
    0

    Default

    1.) Please use code tags when posting code and make sure its formatted.
    Sorry, I change my post.

    2.) What is upMenu?
    UpMenu is name List, UpMenu I transmit in JSTL

    3.) What exception is reported as the cause of the JspException?
    cause JspException == not correct access field Objects List.
    How this make correctly?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    Looks much better now.

    You don't call the getter you just access the property.

    Java Code:
    ${Object.id}

  5. #5
    initmax's Avatar
    initmax is offline Member
    Join Date
    Oct 2009
    Posts
    9
    Rep Power
    0

    Default

    PHP Code:
    <c:out value="${Object.getId}"> </c:out>
    
    method class 
     public int getId() {
            return id;
        }
    names methods identical, who do not this method in JSTL?

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    Quote Originally Posted by initmax View Post
    PHP Code:
    <c:out value="${Object.getId}"> </c:out>
    
    method class 
     public int getId() {
            return id;
        }
    names methods identical, who do not this method in JSTL?
    I don't understand what you mean by that.
    Did you read my post above?

  7. #7
    initmax's Avatar
    initmax is offline Member
    Join Date
    Oct 2009
    Posts
    9
    Rep Power
    0

    Default

    Yes I read your post...
    I don`t understand how JSTL not access to method Object - getId
    ${Object.getId}

    if name methods the same in JSTL and ClassMySQL..

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    Because it's accessing a value (a property). You don't want to display the method but the property's value.

  9. #9
    initmax's Avatar
    initmax is offline Member
    Join Date
    Oct 2009
    Posts
    9
    Rep Power
    0

Similar Threads

  1. Why are we using JSTL in jsp?
    By makpandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-30-2009, 10:15 PM
  2. jstl tag <if>
    By subha in forum Advanced Java
    Replies: 1
    Last Post: 04-02-2009, 09:07 PM
  3. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 09:53 PM
  4. jstl in jsp
    By nagaprasanna in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-18-2008, 09:18 AM
  5. How to access ArrayList in List of List?
    By alvations in forum New To Java
    Replies: 5
    Last Post: 10-08-2008, 12:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •