servlet and jsp sending query result following MVC framework

Posted by kawtousse on Stack Overflow See other posts from Stack Overflow or by kawtousse
Published on 2010-06-01T15:51:38Z Indexed on 2010/06/01 15:53 UTC
Read the original article Hit count: 161

Filed under:

Hi every one, in order to separate java code and html code and be more faithful to MVC framework i am coding like that;

in the servlet i put the following:

net.sf.hibernate.Session s = null;
    net.sf.hibernate.Transaction tx;
    try {

        s= HibernateUtil.currentSession();
        tx=s.beginTransaction();
        Query query = s.createQuery("select  opcemployees.Nom,opcemployees.Prenom,dailytimesheet.TrackingDate,dailytimesheet.Activity," +
                "dailytimesheet.ProjectCode,dailytimesheet.WAName,dailytimesheet.TaskCode," +
                "dailytimesheet.TimeSpent,dailytimesheet.PercentTaskComplete from  Opcemployees opcemployees,Dailytimesheet dailytimesheet  " +
                "where opcemployees.Matricule=dailytimesheet.Matricule  and dailytimesheet.Etat=3 " +
                "group by opcemployees.Nom,opcemployees.Prenom" );  


             for(Iterator it=query.iterate();it.hasNext();)
             {                                                                           
                               if(it.hasNext()){

                                   Object[] row = (Object[]) it.next();
                                   request.setAttribute("items", row);
                               }}
                               } catch (HibernateException e){ 


                            e.printStackTrace();
                            }

request.getRequestDispatcher("EspaceValidation.jsp").forward(request, response);

and in jsp i start like that:

<table>
<c:forEach items="${items}" var="item">
    <tr>
        <td>? </td>
        <td>?</td>
    </tr>
</c:forEach>

in this case what should i put exactly to obtain my result.a table fulled with the right value from the request

© Stack Overflow or respective owner

Related posts about jsp