tags:

views:

69

answers:

2

hi, in my servlet i called an instance of a class.java( a class that construct an html table) in order to create this table in my jsp.

the servlet is like the following:

String report=request.getParameter("selrep");
String datev=request.getParameter("datepicker");
String op=request.getParameter("operator");
String batch =request.getParameter("selbatch");

System.out.println("report kind was:"+report);
System.out.println("date was:"+datev);
System.out.println("operator:"+op);
System.out.println("batch:"+batch);


if(report.equalsIgnoreCase("Report Denied"))
{
    DeniedReportDisplay rd = new DeniedReportDisplay(); 
    rd.ConstruireReport();
}
else if(report.equalsIgnoreCase("Report Locked"))
{
    LockedReportDisplay rl = new LockedReportDisplay(); 
    rl.ConstruireReport();
}

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

in my jsp i can not display this table even empty or full.

note: exemple a class that construct denied Report has this structure:

   /*constructeur*/
                  public DeniedReportDisplay() {}

 /*Methodes*/

 @SuppressWarnings("unchecked")

                 public StringBuffer ConstruireReport()

                 { 
                     StringBuffer retour=new StringBuffer();
                     int i = 0;
                     retour.append("<table border = 1 width=900 id=sheet  align=left>");    
                     retour.append("<tr bgcolor=#0099FF>" );
                     retour.append("<label> Denied Report</label>");
                     retour.append("</tr>");                       
                     retour.append("<tr>"); 

 String[] nomCols ={"Nom","Prenom","trackingDate","activity","projectcode","WAName","taskCode","timeSpent","PercentTaskComplete","Comment"};
 //String HQL_QUERY = null;                      
  for(i=0;i< nomCols.length;i++)
  {
    retour.append(("<td bgcolor=#0066CC>")+ nomCols[i] + "</td>");

   }
  retour.append("</tr>");

     retour.append("<tr>");

                 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();


                         retour.append("<td>" +row [0]+ "</td>");//Nom
                         retour.append("<td>" + row [1] + "</td>");//Prenom
                         retour.append("<td>" + row [2] + "</td>");//trackingdate
                         retour.append("<td>"  +  row [3]+  "</td>");//activity
                         retour.append("<td>"  + row [4] +"</td>");//projectcode
                         retour.append("<td>" +  row [5]+ "</td>");//waname
                         retour.append("<td>" + row [6] + "</td>");//taskcode
                         retour.append("<td>" + row [7] + "</td>");//timespent
                         retour.append("<td>" + row [8] + "</td>");//perecnttaskcomplete
                         retour.append("<td><input type=text /></td>");//case de commentaire
                                     }
                                  retour.append("</tr>");


      }   
 //terminer la table.
                          retour.append ("</table>");

                          tx.commit();


                } catch (HibernateException e) 
                 {
     retour.append ("</table><H1>ERREUR:</H1>" +e.getMessage());
              e.printStackTrace();
                 }

                 return retour;
 }

thanks for help.

+1  A: 

The problem is that you are not doing anything with the return value from ConstruireReport(), so it just get's lost. You should set it as a request attribute so your JSP can find the string.

EDIT: Suggestion to use getWriter() on the servlet removed - misunderstood scenario.

mdma
I am sorry to say, but this answer is *astonishing*. Now he cannot forward to the desired JSP anymore without facing an `IllegalStateException`.
BalusC
I thought this was being called *from* a JSP? I don't do much JSP development, so if I've missed something fundamental please tell me!
mdma
No, read the 1st sentence of his question and the last line of the 1st code snippet.
BalusC
I didn't see the request dispatcher (not suprising given the formatting at the time!).I'm going to remove the advice of using the writer.
mdma
If you correct it, my downvote will go.
BalusC
so i am fully convainced by what you are saying BalusC and i worked with jstl before.my problem is the List report construction and how to store it in a request scope.Iam fortuntally working like that because i need to pass parameter to my query and display the response in table format.i am just trying to have a result and i want to follow your steps BalcusC.But i don't know how could i construct the List that you are talking about and how couls i manipulate it.
kawtousse
could you give me an example more clear to start with the right way.
kawtousse
Go back to the last or one-after-last page of your [question history](http://stackoverflow.com/users/294750/kawtousse) (sorted on *recent*) and review the answers on your questions tagged servlets and/or jsp, starting [here](http://stackoverflow.com/questions/2682069/from-servlet-to-jsp).
BalusC
you mean exactlyy that i construct my query in servlet and after that sending the result to jsp for being displayed with jstl in a table.
kawtousse
if it is like that so i understand you nowelse i am really sorry for disturbing you.
kawtousse
+1  A: 

1) The instances of DeniedReportDisplay and LockedReportDisplay are created locally, no way to refer them once outside the if..else block.

2) The method invoked ( rd.ConstruireReport() ) returns a StringBuffer and you should store it somewhere. Try to use Response.getWriter() and put all the response string into this writer.

3) Suggest you to find some good tutorial books about how to design Servlets/JSP, the solution you tried to build is quite wried.

HZhang
Writing it to response will cause `IllegalStateException` on the `forward()`.
BalusC