Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2995 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  [JSP] Cookie, refresh de page, ...

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[JSP] Cookie, refresh de page, ...

n°1313164
didier1809
${citation_perso}
Posté le 24-02-2006 à 17:27:38  profilanswer
 

:hello:  
 
Ptit problème :
 
Ma page principale comprend une frame sur le coté, avec des liens vers d'autres pages jsp :

Code :
  1. <frame name="FAVORITES" id="FAVORITES" src="<%=layoutPath%>/favo.jsp" marginwidth="0" marginheight="0" frameborder="no" scrolling="auto" noresize>


 
La page favo.jsp est une page de gestion des favoris, on clique sur un bouton sur le site, ca va ajouter une entrée dans le cookie.
 
Problème : Si je ne fait pas "F5" sur la page (qui à pour effet de me demander si je veux ré-envoyer mes identifiant), les modifications apportées dans le cookie ne sont pas lues par la page :(
 
J'ai l'impression qu'à partir du moment ou la page est chargée de la frame, elle ne l'est plus par après  :??:


---------------
.
mood
Publicité
Posté le 24-02-2006 à 17:27:38  profilanswer
 

n°1313525
didier1809
${citation_perso}
Posté le 25-02-2006 à 16:08:45  profilanswer
 

up :)


---------------
.
n°1314015
didier1809
${citation_perso}
Posté le 27-02-2006 à 09:04:00  profilanswer
 

personne ?  :sweat:


---------------
.
n°1314574
didier1809
${citation_perso}
Posté le 27-02-2006 à 16:54:00  profilanswer
 

:hello:


---------------
.
n°1316358
didier1809
${citation_perso}
Posté le 01-03-2006 à 17:14:30  profilanswer
 

Up du soir ...


---------------
.
n°1316382
Bidem
Posté le 01-03-2006 à 17:43:12  profilanswer
 

Chez moi ça marche, mais dans ton cas, il y a un problème ligne 12.
...
 
 
Pour être sérieux, on peu pas vraiment t'aider si tu ne nous montres pas ce que tu as fait...
 
Montre-nous le code de favo.jsp

n°1316968
didier1809
${citation_perso}
Posté le 02-03-2006 à 14:06:46  profilanswer
 

Il y a des fonctions propres à l'environement que j'utilise, donc ca ne compilera probablement pas chez vous ;)
 

Code :
  1. <%@ page
  2. import="
  3.                  javax.servlet.http.Cookie;
  4.     "%>
  5. <%
  6. IBPEnvironment env = (IBPEnvironment)session.getAttribute();
  7. String mode = request.getParameter("mode" );
  8. mode = (null == mode || 0 == mode.length()) ? "show" : mode;
  9. //Ajout d'un favori
  10. if(mode.equalsIgnoreCase("add" )) {
  11.  String modelId = request.getParameter("modelId" );
  12.         String viewKey = request.getParameter("viewKey" );
  13.         model2  = env.getModelContext(modelId, null);
  14.        
  15.  Cookie user2 = new Cookie(env.getExportName(), model2.getGUID());
  16.        
  17.     user2.setMaxAge(1*3600*24*365*10); //-> 1 seconde * 3600 * 24 = 1 jour * 365 = 1an * 10 = 10 ans
  18.  response.addCookie(user2);
  19. } else if(mode.equalsIgnoreCase("del" )) {
  20.  String[] toDel = request.getParameterValues("todel" );
  21.  Cookie[] cookies8 = request.getCookies();
  22.  if ((cookies8 != null)  && (toDel != null)){
  23.    nb_cookie = cookies8.length-1;
  24.    for (int j = 0; j<toDel.length;j++){
  25.     for (int i = 0 ; i < nb_cookie; i++){
  26.      if ( cookies8[i].getValue().equals(toDel[j])  ){
  27.           cookies8[i].setMaxAge(0);
  28.           response.addCookie(cookies8[i]);
  29.      }//Fin If  
  30.     }//Fin for i
  31.    }//fin for j
  32.  }//Fi if != null  
  33. }//fin if del
  34. %>
  35. <%!
  36. int nb_cookie = 0;
  37. String ID;
  38. IBPModelContext model2;
  39. ABPObjectTypeEnum type;
  40. IBPLoginContext loginContext;
  41. int i2 = 0;
  42. %>
  43. <html>
  44. <head>
  45. <title><%=env.getString("BP.favorites.title.DBT" )%></title>
  46. <%= env.genCss("css" )%>
  47. <% if(!mode.equalsIgnoreCase("show" ) && !mode.equalsIgnoreCase("add" )) { %>
  48. <script>
  49. window.setTimeout(
  50. function(){
  51.  parent.frames['TOPNAV'].setModule("fav" );
  52. },
  53. 200
  54. );
  55. </script>
  56. <% } %>
  57. <script>
  58. <% if(mode.equalsIgnoreCase("add" )) { %>
  59. parent.frames['GFX'].setFavoritesMessage('<%=env.getString("BP.favorites.Model.added.STR" )%>');
  60. <% } %>
  61. </script>
  62. </head>
  63. <body bgcolor="#FFFFFF" link="#535D6A" vlink="#535D6A" alink="#535D6A"
  64. topmargin="0" leftmargin="0">
  65. <form action="favo.jsp">
  66. <table border="0" width="600" cellspacing="0" cellpadding="0">
  67. <tr>
  68.  <td valign="top" width="10" style="padding-top:10;"><img border="0"
  69.   src="<%= env.getImgPath()%>/nix.gif" width="10" height="1"></td>
  70.  <td valign="top" width="100%" style="padding-top:10;">
  71.  <div style="width:100%; height: 100%;">
  72.  <table border="0" cellspacing="0" cellpadding="0" width="100%"
  73.   height="100%" bgcolor="#FFFFFF">
  74.   <tr>
  75.    <td valign="middle"><img border="0"
  76.     src="<%= env.getImgPath()%>/txtbl_el.gif" width="11" height="30"></td>
  77.    <td width="100%" background="<%= env.getImgPath()%>/txtbl_o.gif"
  78.     class="blockhead" valign="bottom">
  79.    <table border="0" width="100%" cellspacing="0" cellpadding="0">
  80.     <tr>
  81.      <td class="mytext" valign="middle" height="25"><%=env.getString("BP.favorites.title.DBT" )+" - Work In Progress"%></td>
  82.      <td valign="middle">
  83.      <p align="right"><img border="0"
  84.       src="<%= env.getImgPath()%>/icons/info.gif" width="22"
  85.       height="22">
  86.      </td>
  87.     </tr>
  88.    </table>
  89.    </td>
  90.    <td valign="middle"><img border="0"
  91.     src="<%= env.getImgPath()%>/txtbl_er.gif" width="11" height="30"></td>
  92.   </tr>
  93.   <tr>
  94.    <td background="<%= env.getImgPath()%>/txtbl_l.gif"><img border="0"
  95.     src="<%= env.getImgPath()%>/nix.gif" width="1" height="1"></td>
  96.    <td width="100%" height="100%">
  97.    <table border="0" width="100%">
  98.     <tr>
  99.      <td valign="top" bgcolor="#FFFFFF">&nbsp;</td>
  100.      <td width="70%" valign="top" bgcolor="#FFFFFF"><%= env.getString("BP.favorites.tablecolumn.name.DBI" ) %></td>
  101.      <td width="30%" bgcolor="#FFFFFF">Type</td>
  102.      <td bgcolor="#FFFFFF">&nbsp;</td>
  103.     </tr>
  104. <!-- Loop --> 
  105. <%
  106. Cookie[] cookies = request.getCookies();
  107. if (cookies != null){
  108. nb_cookie = cookies.length-1;
  109. for (int i = 0 ; i < nb_cookie; i++){
  110.  String GUID = cookies[i].getValue();
  111.  model2 = null;
  112.  model2  = env.getModelContext(ID, null);
  113. if (model2 != null){
  114.  %>
  115.  <tr>
  116.   <td valign="top"><img border="0"
  117.    src="<%= env.getImgPath()%>/icons/mod.gif" width="15" height="15"></td>
  118.   <td><a
  119.    href="<%= env.getLayoutPath()%>/mod_gfx.jsp?modelId=<%= cookies[i].getValue()%>&viewKey="
  120.    target="GFX"> <%= model2.getName(), env) %>
  121.   </a></td>
  122.   <td><%=  model2.getTypeName()%></td>
  123.   <td valign="top" colspan="2"><input type="checkbox" name="todel"
  124.    value="<%= cookies[i].getValue()%>"></td>
  125.  </tr>
  126. <%
  127. }
  128. }
  129. }
  130. %>
  131. <!-- LoopEnd -->
  132.     <tr>
  133.      <td valign="top" bgcolor="#FFFFFF">&nbsp;</td>
  134.      <td width="100%" valign="top" bgcolor="#FFFFFF" colspan="3"
  135.       align="right"><input type="hidden" value="del" name="mode"> <input
  136.       type="submit" value="<%="Delete favorites"%>"
  137.       name="S1" class="searchbutton" style="width: 200px"> <img
  138.       border="0" src="<%= env.getImgPath()%>/selcorn.gif" width="20"
  139.       height="18"></td>
  140.     </tr>
  141.    </table>
  142.    </td>
  143.    <td background="<%= env.getImgPath()%>/txtbl_r.gif"><img border="0"
  144.     src="<%= env.getImgPath()%>/nix.gif" width="1" height="1"></td>
  145.   </tr>
  146.   <tr>
  147.    <td><img border="0" src="<%= env.getImgPath()%>/txtbl_elu.gif"
  148.     width="11" height="6"></td>
  149.    <td width="100%" background="<%= env.getImgPath()%>/txtbl_u.gif"><img
  150.     border="0" src="<%= env.getImgPath()%>/nix.gif" width="1"
  151.     height="1"></td>
  152.    <td><img border="0" src="<%= env.getImgPath()%>/txtbl_elr.gif"
  153.     width="11" height="6"></td>
  154.   </tr>
  155.  </table>
  156.  </div>
  157.  </td>
  158.  <td valign="top" width="10" style="padding-top:10;"><img border="0"
  159.   src="<%= env.getImgPath()%>/nix.gif" width="10" height="1"></td>
  160. </tr>
  161. </table>
  162. </form>
  163. </body>
  164. </html>


 


---------------
.
n°1317072
Bidem
Posté le 02-03-2006 à 15:38:18  profilanswer
 

Quand tu ajoutes un nouveau favoris (mode 'add') la liste que tu récupères avec "Cookie[] cookies = request.getCookies();" n'est pas à jour (ca te donne la liste des favoris AVANT le dernier ajout)
 
Par exemple lors du 1er ajout :
 - l'ajout se passe bien
 - cookies = request.getCookies();
     => cookies == null car avant il n'y avait rien
 
Ce que tu dois faire, c'est modifier le mécanisme d'affichage pour prendre en compte les favoris ajoutés (ou supprimer) au début du traitement de la jsp


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  [JSP] Cookie, refresh de page, ...

 

Sujets relatifs
[JSP] [résolu] cookie, plusieurs valeurs ?affichage page par page, trie
Retour vers l'index si la page n'est pas dans une frameaide pour faire une applet pour ouvrir word à partir de page html
Comment ajouter une page [RESOLU]Musique de fond pour page html
Insérer du texte récurrent dans une page par les CSS ?recherche de script pour page web
afficher un page html dans un calque (div) avec un lien 
Plus de sujets relatifs à : [JSP] Cookie, refresh de page, ...


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR