¿Todavía necesitamos hacer la codificación de URL (para la ID de sesión) con Servlet 3.0?

Estoy leyendo un libro sobre Servlets para revisar y dice que decidirá automáticamente cuándo agregar la ID de sesión. He leído declaraciones contradictorias en la web. ¿Hasta qué punto agregará la ID de sesión a las URL automáticamente cuando se bloqueen las cookies? ¿Incluirá esto el uso de sendRedirect()? Me refiero a la versión más reciente. Revisé The JAVA Docs en Oracle.com, pero no estoy seguro de si se han actualizado recientemente.

Gracias :-)

preguntado el 04 de julio de 12 a las 06:07

1 Respuestas

No, el contenedor no tiene inteligencia para detectar los enlaces en su plantilla de texto o cadena que escribe en el flujo de salida.

Para Ex, tome este código de muestra:

servletoutputStream.write("<form method=\"post\" action=\"/submit.jsp\");

En el código anterior, tienes que hacer HttpServletResponse.encodeURL("/submit.jsp") tener una identificación de sesión en la URL de acción posterior.

Del mismo modo, la Documentación API para HttpServletResponse.encodeRedirectURL() Eso dice

java.lang.String encodeRedirectURL(java.lang.String url)

   Encodes the specified URL for use in the sendRedirect method or, if encoding 
     is not needed, returns the URL unchanged. The implementation of this method 
     includes the logic to determine whether the session ID needs to be encoded in 
     the URL.Because the rules for making this determination can differ from those 
     used to decide whether to encode a normal link, this method is separated from 
     the encodeURL method.

   All URLs sent to the HttpServletResponse.sendRedirect method should be run 
   through this method. Otherwise, URL rewriting cannot be used with browsers 
   which do not support cookies. 

Referencias:

Respondido 04 Jul 12, 06:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.