'how to convert Calendar type to String?

i tried to convert calendar type to String for display the date in my jsp page

here is my servlet code where i convert string to calendar type

private Evaluation EvaluationMapper(HttpServletRequest request)
{

        try {
            Evaluation eval = new Evaluation();
            eval.setNumero(Integer.parseInt(request.getParameter("numero")));
            eval.setNom(request.getParameter("nom"));
            eval.setPrenom(request.getParameter("prenom"));
            eval.setTelephone(request.getParameter("telephone"));
            eval.setCourriel(request.getParameter("courriel"));
            eval.setSexe(request.getParameter("sexe").charAt(0));
            eval.setNote(request.getParameter("note"));

            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Calendar cal = Calendar.getInstance();
            cal.setTime(df.parse(request.getParameter("date")));
            eval.setDateEvaluation(cal);

            eval.setCommentaire(request.getParameter("commentaires"));

            return eval;
        } catch (ParseException ex) {
            throw new IllegalArgumentException("Erreur..??");
        }


}

and here is my code for my jsp page but its didn't display the date

 <% for(Evaluation e:(List<Evaluation>)request.getAttribute("ListeEvaluation")){%>
           <tr><td><%= e.getNumero()%> </td>
               <td><%= e.getNom() %> </td>
               <td><%= e.getPrenom()%> </td>
               <td><%= e.getTelephone()%> </td>
               <td><%= e.getCourriel()%> </td>
               <td><%= e.getSexe()%> </td>
               <td><%= e.getNote()%> </td>
               <td><%= e.getDateEvaluation()%> </td>
               <td><%= e.getCommentaire()%> </td>
               <td>
                   <a href="/Labo2/SupprimerServlet?numero=<%= e.getNumero()%>" >Supprimer</a> |
                   <a href="/Labo2/ModifierServlet?numero=<%= e.getNumero()%>" >Modifier</a>
               </td>
           </tr>               
           <%}%>

here my listEvaluation

private static  List<Evaluation> ListeEvaluation = new ArrayList<Evaluation>();

public Evaluation evaluation = new Evaluation();


//set method
 public void setListeEvaluation(List value){this.ListeEvaluation = value;}

 //getmethod
 public List<Evaluation> getListeEvaluation(){return this.ListeEvaluation;}

so how cant i convert getDateEvaluation in string?



Solution 1:[1]

If you want to get values of attribute "ListeEvaluation" from request in JSP as follows:

<% for(Evaluation e:(List<Evaluation>)request.getAttribute("ListeEvaluation")){%>

you should set attribute "ListeEvaluation" in your servlet:

List<Evaluation> listeEvaluation = new ArrayList<>();
for (...) {
    Evaluation evaluation = new Evaluation();
    evaluation.setNumero(...);
    evaluation.setNom(...);
    ...
    listeEvaluation.add(evaluation);
}
request.setAttribute("ListeEvaluation", listeEvaluation);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kohei TAMURA