0

I would like to translate the date (usa) in french format.I don't know how to do it ? I have 3 files. I see that some use the javascript ??? I want to do in jsp it's possibl? In My DataBase is the variable "naissance_eleve" is in varchar

eleve_form.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

</head>
<body>


<a href="vueEleve.jsp">Apercu des infos</a><br/>


<form action="ajoutEleve.jsp" method="post">
    <table border="1" width="40%">
        <tr><td>Nom:</td><td><input type="text" name="nom_eleve"/></td></tr>
        <tr><td>Prenom</td><td><input type="text" name="prenom_eleve"/></td></tr>
        <tr><td>Date Naissance</td><td><input type="date" name="naissance_eleve"/></td></tr>
        <tr><td colspan="2"><input type="submit" value="Ajouter"/></td></tr>
    </table>
</form>

</body>
</html>

eleve_form.html

<!DOCTYPE html>
<html>
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

</head>
<body>


</body>
</html>

<%@ page pageEncoding="UTF-8" %>
<%@page import="com.java.bd.EleveBD"%>
<jsp:useBean id="u" class="com.java.classe.Eleve"></jsp:useBean>
<jsp:setProperty property="*" name="u"/>

<%
    int i= EleveBD.add(u);
    if(i>0){
        response.sendRedirect("success.jsp");
    }else{
        response.sendRedirect("erreur.jsp");
    }
%>

vueEleve.jsp

<table border="1" width="40%">
        <thead>
        <tr>
    <th>Id</th><th>Nom</th>
        <th>Prenom</th><th>Date Naissance</th><th>Editer</th><th>Supprimer</th>
        </tr>
        </thead>
    <c:forEach items="${list}" var="eleve">
        <tr><td>${eleve.getPk_eleve()}</td><td>${eleve.getNom_eleve()}</td>
            <td>${eleve.getPrenom_eleve()}</td><td>${eleve.getNaissance_eleve()}</td>

            <td><a href="edit_form_ecole.jsp?getPk_eleve=${eleve.getPk_eleve()}">Editer</a></td>
            <td><a href="delete_ecole.jsp?pk_eleve=${eleve.getPk_eleve()}">Supprimer</a></td></tr>



    </c:forEach>
</table>
tamzoro
  • 45
  • 7
  • "naissance_eleve" should probably better be of type DATE in your database. If you cannot change that, I assume "naissance_eleve" is always in ISO, i.e. like '2017-12-3' etc.? Then you use java.text.SimpleDateFormat for conversion. – Heiko Jakubzik Dec 03 '17 at 13:01
  • @HeikoJakubzik Actually, standard [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format pads with leading zeros, so make that `2017-12-03`. – Basil Bourque Dec 04 '17 at 05:52

1 Answers1

0

I'm not exactly sure how to translate this into JSP. I do remember that JSPs can contain Java. This sample of Java code creates a SimpleDateFormat of two locales, US and France, parses and formats the date and outputs the result.

public static void main(String[] args)
{

  Date d = new Date();
  SimpleDateFormat sdf_us = new SimpleDateFormat("yyyy-MMMM-dd",Locale.US);
  SimpleDateFormat sdf_fr = new SimpleDateFormat("yyyy-MMMM-dd",Locale.FRANCE);
  String output = sdf_us.format(d);
  System.out.println(output);
  System.out.println(d);
  try
  {
    d = sdf_us.parse(output);
    String output_fr = sdf_fr.format(d);
    d = sdf_fr.parse(output_fr);
    System.out.println(output_fr);
    System.out.println(d);
  }
  catch (ParseException e)
  {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}

The output is

2017-December-03

Sun Dec 03 07:15:57 CST 2017

2017-décembre-03

Sun Dec 03 00:00:00 CST 2017

No time appears in the last one because it was removed when the format didn't cover it.

My guess would be

    <tr><td>Date Naissance</td><td><input type="date" name="naissance_eleve" value="
<%      
  SimpleDateFormat sdf_fr = new SimpleDateFormat("yyyy-MMMM-dd",Locale.FRANCE);
  String output = sdf_fr.format(naissance_eleve);
  out.print(output);

%>"/></td></tr>
ProgrammersBlock
  • 5,974
  • 4
  • 17
  • 21