IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Servlets/JSP Java Discussion :

formater une date dans une page JSP


Sujet :

Servlets/JSP Java

  1. #1
    Membre éclairé
    Avatar de clavier12AZQSWX
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2009
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Avril 2009
    Messages : 1 391
    Points : 863
    Points
    863
    Par défaut formater une date dans une page JSP
    bonjour,

    je dois modifier le format d'une date issue d'un micro-code java JSP incrusté dans une page html.

    Pouvez-vous m'aider svp, je ne connais pas du tout ce language.

    Voiçi la ligne de code où apparaît l'écriture de la date :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td valign="bottom" align="right"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><bean:message key="jsp.report.newUser.jsp.GeneratedAt" /> <%= new java.util.Date() %></font></td>
    pour l'instant cette dernière apparaît ainsi :
    Généré le : Tue Nov 02 13:59:00 CET 2010
    J'aimerais avoir e format :
    Mardi 02 novembre 2010 à 13h59m00s (PARIS)

    est-ce possible ?

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    il suffit d'utiliser la classe SimpleDateFormat pour formater ta date.

  3. #3
    Membre éclairé
    Avatar de clavier12AZQSWX
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2009
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Avril 2009
    Messages : 1 391
    Points : 863
    Points
    863
    Par défaut
    Citation Envoyé par tchize_ Voir le message
    il suffit d'utiliser la classe SimpleDateFormat pour formater ta date.

    comme dit précédement, je ne connais pas java...

    comment modifier juste la ligne <%= new java.util.Date() %> pour formater la date ?

    je ne peux pas me permettre d'ajouter des class , des lib, je n'ai le droit à aucun risque sur le serveur. je dois juste localiser/traduire la page html et la date auto en fait parti.

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    http://java.developpez.com/faq/java/...version_string


    Manipuler une application web java, sans maitriser java, c'est dagenreux et pas vraiment le bon plan

  5. #5
    Membre éclairé
    Avatar de clavier12AZQSWX
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2009
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Avril 2009
    Messages : 1 391
    Points : 863
    Points
    863
    Par défaut
    bonjour,

    merci de votre aide. c'est pas comme si je ne savais pas ce que je fais, c'est pour ça que je pose la question ici avant de tenter quoi que ce soit. je maîtrise php,html, javascript, css...mais pas java/jsp.
    Comme dit plus haut, je ne peux pas me permettre de faire une erreur (bug serveur) juste pour une date, donc j'ai besoin d'assurer mon coup et je ne peux pas importer n'importe quelle librairie dans le projet.

    voilà le jsp complet de page où je dois modifier la date, est-ce que ma modif est envisageable dedans, si oui comment exactement (merci d'apporter une réponse efficiente et non pas une réponse efficace)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
     
    <%@ page language="java" %>
    <%@ page import="java.util.Locale" %>
    <%@ page import="com.ahsay.obs.www.Resource" %>
    <%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
    <%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %>
     
    <%
        String sLocale = Resource.getLocaleName(request);
        String sCharSet = Resource.getCharSetName(request);
        response.setContentType("text/html; charset=" + sCharSet);
        response.addHeader("Pragma","No-cache");
        response.addHeader("Cache-Control","no-cache");
        response.addHeader("Expires","1");
        String sHomepage = "http://" + Resource.getHostname();
    %>
     
    <bean:define id="getBackupQuotaReminderReportForm" name="getBackupQuotaReminderReportForm"
    type="com.ahsay.obs.www.report.bean.GetBackupQuotaReminderReportForm"/>
     
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=<%= sCharSet %>">
        <meta http-equiv="Content-Language" content="<%= sLocale %>">
    </head>
     
    <body bgcolor="#FFFFFF">
        <table border="0" cellpadding="0" cellspacing="0" width="650">
            <tr>
                <td rowspan="2"><a href="<%= sHomepage %>"><img border="0" src="<bean:write name="getBackupQuotaReminderReportForm" property="embedLogoLink"/>" hspace="2" vspace="2"></a></td>
                <td valign="top" align="left"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 20px" color="#db6a15"><bean:message key="jsp.report.backupQuotaReminder.jsp.Title"/></font></td>
            </tr>
            <tr>
                <td valign="bottom" align="right"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><bean:message key="jsp.report.backupQuotaReminder.jsp.GeneratedAt"/> <%= new java.util.Date() %></font></td>
            </tr>
        </table>
        <table border="0" cellpadding="5" width="650" cellspacing="0">
            <tr>
                <td valign="top">
                    <p style="font-family: Arial; font-size: 12px"><b><u><bean:message key="jsp.report.backupQuotaReminder.jsp.BackupQuotaTitle"/><bean:message key="GLOBAL.Label.Colon"/></u></b></p>
                    <p style="font-family: Arial; color: red; font-weight: bold; font-style: normal; font-size: 12px"></p>
                    <p style="font-family: Arial; color: red; font-weight: bold; font-size: 12px">
                        <bean:message key="jsp.report.backupQuotaReminder.jsp.BackupQuota"/>&nbsp;
                        <bean:message key="jsp.report.backupQuotaReminder.jsp.over"/>&nbsp;
                        <nested:write name="getBackupQuotaReminderReportForm" property="percentage" />&nbsp;
                        <bean:message key="GLOBAL.Label.Percent"/>
                    </p>
                    <table border="0" width="300">
                        <tr>
                            <td colspan="2"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><b><bean:message key="jsp.report.backupQuotaReminder.jsp.FAQs"/></b></font></td>
                        </tr>
                        <tr>
                            <td valign="top"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#db6a15"><b><bean:message key="GLOBAL.Label.1"/>.</b></font></td>
                            <td valign="top"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><font color="#db6a15"><b><bean:message key="jsp.report.backupQuotaReminder.jsp.FAQs.Q1"/>
                                </b></font><br><bean:message key="jsp.report.backupQuotaReminder.jsp.FAQs.A1"/><br></font>
                            </td>
                        </tr>
                    </table>
                </td>
                <td valign="top" rowspan="2" align="right">
                    <table border="0" cellspacing="0" width="290">
                        <tr>
                            <td colspan="3" bgcolor="#666666"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#FFFFFF"><b>&nbsp;<bean:message key="jsp.report.backupJobReminder.jsp.UserSetting"/></b></font></td>
                        </tr>
                        <tr>
                            <td valign="top" bgcolor="#FFFFEE"><div style="width: 120; height: 1"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">&nbsp;<bean:message key="GLOBAL.UserProfile.LoginName"/></font></div></td>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><b>:</b></font></td>
                            <td><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#db6a15"><nested:write name="getBackupQuotaReminderReportForm" property="userInfo.loginName"/></font></td>
                        </tr>
                        <tr>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">&nbsp;<bean:message key="GLOBAL.UserProfile.Alias"/></font></td>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><b>:</b></font></td>
                            <td><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#db6a15"><nested:write name="getBackupQuotaReminderReportForm" property="userInfo.alias"/></font></td>
                        </tr>
                        <tr>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">&nbsp;<bean:message key="GLOBAL.UserProfile.Language"/></font></td>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><b>:</b></font></td>
                            <td><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#db6a15">
    							<bean:message key="<%=Resource.getLanguagePropertyName(getBackupQuotaReminderReportForm.getUserInfo().getLanguage()) %>"/>
                                </font>
                            </td>
                        </tr>
                        <tr>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">&nbsp;<bean:message key="GLOBAL.UserProfile.Contact"/></font></td>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><b>:</b></font></td>
                            <td><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#db6a15">
                                <nested:iterate id="contact" name="getBackupQuotaReminderReportForm" property="userInfo.contacts">
                                    <bean:write name="contact" /><br>
                                </nested:iterate>
                                </font>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3"></td>
                        </tr>
                        <tr>
                            <td colspan="3" bgcolor="#666666"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#FFFFFF"><b>&nbsp;<bean:message key="jsp.report.backupJobReminder.jsp.BackupStatistics"/></b></font></td>
                        </tr>
                        <tr>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">&nbsp;<bean:message key="GLOBAL.UserProfile.DataArea"/>*</font></td>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><b>:</b></font></td>
                            <td><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#db6a15">&nbsp;<nested:write name="getBackupQuotaReminderReportForm" property="userInfo.dataFileNo"/> [ <nested:write name="getBackupQuotaReminderReportForm" property="userInfo.dataSize"/> ] </font></td>
                        </tr>
                        <tr>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">&nbsp;<bean:message key="GLOBAL.UserProfile.RetentionArea"/>*</font></td>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><b>:</b></font></td>
                            <td><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#db6a15">&nbsp;<nested:write name="getBackupQuotaReminderReportForm" property="userInfo.retainFileNo"/> [ <nested:write name="getBackupQuotaReminderReportForm" property="userInfo.retainSize"/> ] </font></td>
                        </tr>
                        <tr>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">&nbsp;<bean:message key="GLOBAL.UserProfile.BackupQuota"/></font></td>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><b>:</b></font></td>
                            <td><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#db6a15">&nbsp;<nested:write name="getBackupQuotaReminderReportForm" property="userInfo.quota"/></font></td>
                        </tr>
                        <tr>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">&nbsp;<bean:message key="GLOBAL.UserProfile.RemainingQuota"/></font></td>
                            <td valign="top" bgcolor="#FFFFEE"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px"><b>:</b></font></td>
                            <td><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px" color="#db6a15">&nbsp;<nested:write name="getBackupQuotaReminderReportForm" property="userInfo.remainQuota"/></font></td>
                        </tr>
                        <tr>
                            <td colspan="3" align="right"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">* <bean:message key="jsp.report.backupJobReminder.jsp.BackupJobStatistics.Unit"/></font></td>
                        </tr>
                        <tr>
                            <td colspan="3"></td>
                        </tr>
                    </table>
                </td>
            </tr>
    		<!--
            <tr>
                <td valign="top"><font style="font-family: Arial; font-weight: normal; font-style: normal; font-size: 12px">
                    <bean:message key="jsp.report.backupJobReminder.jsp.FAQs.FurtherInfo" arg0='<%= sHomepage %>' />
                    </font>
                </td>
            </tr>
    		-->
        </table>
    </body>
    </html>

  6. #6
    Membre chevronné
    Homme Profil pro
    Dév. Java & C#
    Inscrit en
    Octobre 2002
    Messages
    1 413
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Dév. Java & C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2002
    Messages : 1 413
    Points : 1 993
    Points
    1 993
    Par défaut
    Bonjour,

    Mon conseil est de créer une page JSP (par exemple testMRemy.jsp) et la placer dans le répertoire du fichier à modifier.

    Vous pouvez faire vos tests, en espérant que la page sera compilée et executée.

    Code NON testé
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    <%@ page language="java" %>
    <%@ page import="java.text.SimpleDateFormat" %>
    <%@ page import="java.util.Locale" %>
    <%@ page import="java.util.Date" %>
    <%@ page import="com.ahsay.obs.www.Resource" %>
     
    <%
           final String sLocale = Resource.getLocaleName(request);
           final Locale locale = new Locale(sLocale);
           final Date dNow = new Date();
           final formatLong = new SimpleDateFormat("", locale)
           final String sNow = formatLong.format(dNow);
    %>
    <hr>
    Date "<%=sNow>"<br>
    Code testé
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ page import="java.text.SimpleDateFormat" %>
    <%@ page import="java.util.Locale" %>
    <%@ page import="java.util.Date" %>
    <%
           final Locale locale = Locale.getDefault();
           final Date dNow = new Date();
           final SimpleDateFormat formatLong = new SimpleDateFormat("EEEE dd MMMM yyyy 'a' HH'h'mm'm'ss's' zzzz", locale);
           final String sNow = formatLong.format(dNow);
    %>
    <%= sNow %><br>
    La page me retourne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    mercredi 03 novembre 2010 a 15h07m55s Heure d'Europe centrale
    Il reste à régler le problème de "(Paris)"
    Bien le bonjour chez vous
    Jowo

  7. #7
    Membre éclairé
    Avatar de clavier12AZQSWX
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2009
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Avril 2009
    Messages : 1 391
    Points : 863
    Points
    863
    Par défaut
    merci de votre aide,

    je vais voir comment je peux tester cela (car le jsp sert à générer un email html)...
    facile à tester unitairement.

Discussions similaires

  1. [MySQL] insérer une date dans une table dans un format compréhensible
    Par laurentSc dans le forum PHP & Base de données
    Réponses: 13
    Dernier message: 16/08/2014, 11h10
  2. insérer une date dans une table dans un format compréhensible
    Par laurentSc dans le forum Langage SQL
    Réponses: 5
    Dernier message: 08/08/2014, 16h31
  3. Formater l'affichage d'une date dans une vue
    Par ripcurl dans le forum Requêtes
    Réponses: 2
    Dernier message: 31/05/2010, 16h57
  4. Réponses: 3
    Dernier message: 29/04/2008, 14h14
  5. Inserer une date d'une table dans une autre table
    Par petitetre dans le forum Langage SQL
    Réponses: 8
    Dernier message: 18/04/2007, 20h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo