0

I need to call a class form jsp for which i don't want to use scriptlets.I am not sure either to use tld here or something else . I just need a hint

So using sciplets it was like this in jsp

<table width="99%" border="0" cellspacing="0" cellpadding="0">
 <%   sql= "select class,period,sub from timetable where uid='"+uid+"' " ;
                           rs = stmt.executeQuery(sql) ;
                           while (rs.next()) {      
                           %>

                            <tr>
                              <td class="table_img"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="33%" height="19" class="notice_text"><div align="center"><%=rs.getString(2)%></div></td>
                                  <td width="29%" class="notice_text"><div align="center"><%=rs.getString(1)%></div></td>
                                  <td width="38%" class="notice_text"><div align="center"><%=rs.getString(3)%></div></td>
                                </tr>
                              </table></td>
                            </tr> 
                            <%                 }            %>
                          </table>    

So at first i create a class and function which fetches this data like this

public class TrHome extends ConnectionClass{


    public List<TimeTablePojo> getTimeTableDetails(String scid, String uid){
        Statement statement = getStatement();//getting connection form extended class
        ResultSet resultSet = null;
        String query = "select class,period,sub from timetable where uid='"+uid+"' " ;
        List<TimeTablePojo> listPojo = new ArrayList<TimeTablePojo>();
        try{
        resultSet = statement.executeQuery(query);
            while(resultSet.next()){
                TimeTablePojo tPojo = new TimeTablePojo();
                tPojo.setClas(resultSet.getString(1));
                tPojo.setPeriod(resultSet.getInt(2));
                tPojo.setSub(resultSet.getString(3));
                listPojo.add(tPojo);
            }
        }catch(SQLException se){
            System.err.println("sql exception in getTimeTableDetails(String scid, String uid) in TrHome.java : "+se);
        }finally{
            closeResultSet(resultSet);
            closeConnection();//closing connection
        }
        return listPojo;
    }

}   

But now i don't any idea how to create object of this class and call this function to get data in jsp.Well after geting data i can iterate it using jstl but problem is how to call this function. As per my understanding i have to create tld .Is that right or there is a way through? Also I don't want to set data in request in servlet.

1 Answer 1

2

.You can use 'useBean' to access the class in the jsp,then you can call the method of the class by passing the parameters and process the

<jsp:useBean id="connBean" 
                class="packageName.TrHome ">

The method will return the list on which you can iterate in the jsp.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay but how can I pass two paramters to my function as using jsp:setPropery I can set one parameter of bean only
Thanks I got it <jsp:useBean id="home" class="com.escolo.tr.TrHome" scope="page"/> <c:forEach items="${home.getTimeTableDetails('scid', 'suid')}" var="item"> ${item.period} </c:forEach>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.