You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Anson Zeall <ze...@bigpond.net.au> on 2003/09/10 03:56:15 UTC

The function for response.encodeURL....me still not sure

Hi guys,

    I was asking about the login stuff before from previous emails and
trying to avoid the use of cookies. Someone in the group asked me to try and
use sessions ...using response.encodeURL and stuff. Can someone explain a
bit more what that does, or is there a site that can explain to me about
that?



Thanks,

Anson

Re: The function for response.encodeURL....me still not sure

Posted by Christopher Williams <cc...@ntlworld.com>.
You don't use encodeURL() with the include directive.  The include directive
takes a relative path straight to the appropriate JSP and has the same
effect as, say, "#include <stdio.h>" in C code, i.e. the included file is
added to your source prior to compilation.  You couldn't write C code like
the following:

    char *include_file = "<stdio.h>";
    #include include_file

And you can't do something similar with JSP files either:
    <%
    String included_page = "header.jsp";
    %>
    <%@ include file=included_page %>

An even more obviously absurd example might be:
    <%
    String importedPackage = "java.util.";
    %>
    <%@ page import=importedPackage + "Properties" %>
    <%@ page import=importedPackage + "Vector" %>

Even if the JSP compiler accepted this (it won't), the output would be:
    String importedPackage = "java.util.";
    import importedPackage + "Properties";
    import importedPackage + "Vector";

which is illegal Java.  However, that dumb example is conceptually the same
as your
<%@ include file="<%= response.encodeURL("header_status_register.jsp")%>" %>
(please note, I'm not saying that you're dumb, simply that a dumb example
can be used to illustrate a technical point).

The JSP <%@ ... %> directives are handled by a pre-processor, just like C
#include statements and the pre-processor does not evaluate Java (or C)
expressions.

You only use encodeURL() for links and encodeRedirectURL() for redirects.

You may want to get a good book on Servlet and JSP programming.  I use the
O'Reilly volumes 'Java Servlet Programming' and 'JavaServer Pages'.
Doubtless there are other good titles but you can never go far wrong with an
O'Reilly, I always say.

----- Original Message ----- 
From: "Anson Zeall" <ze...@bigpond.net.au>
To: "'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Wednesday, September 10, 2003 10:17 AM
Subject: RE: The function for response.encodeURL....me still not sure


> Thanks a lot,
>
> But......for example...if I have a jsp file..that includes another jsp
> file in it.....how can I write it with encodeURL? Doesn't seem to work..
>
> E.g.
> <%@ include file="<%= response.encodeURL("header_status_register.jsp")
> %>" %> doesn't work
>
> Anson
>
> -----Original Message-----
> From: Christopher Williams [mailto:ccwilliams3@ntlworld.com]
> Sent: Wednesday, September 10, 2003 5:55 PM
> To: Tomcat Users List
> Subject: Re: The function for response.encodeURL....me still not sure
>
>
> As I said, the URL-rewriting is done by the container to allow you to
> use HTTP sessions when the user of your site has disabled cookies and it
> does this by appending ";jessionid=blah-blah-blah" to end of your URLs
> prior to the query string ("?blah=stuff&jabber=yakka-yakka...").  This
> is all in the servlet spec.  However, you need to give the container the
> opportunity to do so and for this you need to use the encodeURL methods
> of HttpServletResponse.
>
> Think about your JSPs.  Currently (presumably) you have links like the
> following:
>     <a href="some_link.jsp">Some link</a>
>
> To enable session tracking without cookies, all you need to do is:
>     <a href="<%= response.encodeURL("some_link.jsp") %>">Some link</a>
>
> Likewise, whenever the logic of your page indicates that a redirect is
> required, instead of calling:
>     response.sendRedirect("some_link.jsp");
> you call
>     response.sendRedirect(response.encodeRedirectURL("some_link.jsp"));
>
> Check out the J2EE tutorial for examples:
> http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets11.html#63281
>
> Chris.
>
> ----- Original Message -----
> From: "Anson Zeall" <ze...@bigpond.net.au>
> To: "Tomcat Users List" <to...@jakarta.apache.org>
> Sent: Wednesday, September 10, 2003 2:56 AM
> Subject: The function for response.encodeURL....me still not sure
>
>
> > Hi guys,
> >
> >     I was asking about the login stuff before from previous emails and
>
> > trying to avoid the use of cookies. Someone in the group asked me to
> > try
> and
> > use sessions ...using response.encodeURL and stuff. Can someone
> > explain a bit more what that does, or is there a site that can explain
>
> > to me about that?
> >
> >
> >
> > Thanks,
> >
> > Anson
> >
> >
>
>
> ------------------------------------------------------------------------
> ----
> ----
>
>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



RE: The function for response.encodeURL....me still not sure

Posted by Anson Zeall <ze...@bigpond.net.au>.
Hi guys,

Thanks a lot Jon and Chris. I'm very new to JSP...so...barely with me
for the stupid questions. I don't mind being called stupid...i'll learn
=P haha...

Anson

-----Original Message-----
From: Jon Wingfield [mailto:jon.wingfield@mkodo.com]
Sent: Wednesday, September 10, 2003 7:53 PM
To: Tomcat Users List
Subject: Re: The function for response.encodeURL....me still not sure


You don't need to use encodeURL for includes or forwards. These are
server side processes and the session has already been determined. The
encodeURL tags the *next* client request with the data required to
continue a session.

HTH,

Jon

Anson Zeall wrote:

> Thanks a lot,
>
> But......for example...if I have a jsp file..that includes another jsp

> file in it.....how can I write it with encodeURL? Doesn't seem to
> work..
>
> E.g.
> <%@ include file="<%= response.encodeURL("header_status_register.jsp")
> %>" %> doesn't work
>
> Anson
>
> -----Original Message-----
> From: Christopher Williams [mailto:ccwilliams3@ntlworld.com]
> Sent: Wednesday, September 10, 2003 5:55 PM
> To: Tomcat Users List
> Subject: Re: The function for response.encodeURL....me still not sure
>
>
> As I said, the URL-rewriting is done by the container to allow you to
> use HTTP sessions when the user of your site has disabled cookies and
> it does this by appending ";jessionid=blah-blah-blah" to end of your
> URLs prior to the query string ("?blah=stuff&jabber=yakka-yakka...").

> This is all in the servlet spec.  However, you need to give the
> container the opportunity to do so and for this you need to use the
> encodeURL methods of HttpServletResponse.
>
> Think about your JSPs.  Currently (presumably) you have links like the
> following:
>     <a href="some_link.jsp">Some link</a>
>
> To enable session tracking without cookies, all you need to do is:
>     <a href="<%= response.encodeURL("some_link.jsp") %>">Some link</a>
>
> Likewise, whenever the logic of your page indicates that a redirect is

> required, instead of calling:
>     response.sendRedirect("some_link.jsp");
> you call
>
> response.sendRedirect(response.encodeRedirectURL("some_link.jsp"));
>
> Check out the J2EE tutorial for examples:
> http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets11.html#63281
>
> Chris.
>




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



Re: The function for response.encodeURL....me still not sure

Posted by Jon Wingfield <jo...@mkodo.com>.
You don't need to use encodeURL for includes or forwards. These are 
server side processes and the session has already been determined. The 
encodeURL tags the *next* client request with the data required to 
continue a session.

HTH,

Jon

Anson Zeall wrote:

> Thanks a lot,
> 
> But......for example...if I have a jsp file..that includes another jsp
> file in it.....how can I write it with encodeURL? Doesn't seem to work..
> 
> E.g.
> <%@ include file="<%= response.encodeURL("header_status_register.jsp")
> %>" %> doesn't work
> 
> Anson
> 
> -----Original Message-----
> From: Christopher Williams [mailto:ccwilliams3@ntlworld.com]
> Sent: Wednesday, September 10, 2003 5:55 PM
> To: Tomcat Users List
> Subject: Re: The function for response.encodeURL....me still not sure
> 
> 
> As I said, the URL-rewriting is done by the container to allow you to
> use HTTP sessions when the user of your site has disabled cookies and it
> does this by appending ";jessionid=blah-blah-blah" to end of your URLs
> prior to the query string ("?blah=stuff&jabber=yakka-yakka...").  This
> is all in the servlet spec.  However, you need to give the container the
> opportunity to do so and for this you need to use the encodeURL methods
> of HttpServletResponse.
> 
> Think about your JSPs.  Currently (presumably) you have links like the
> following:
>     <a href="some_link.jsp">Some link</a>
> 
> To enable session tracking without cookies, all you need to do is:
>     <a href="<%= response.encodeURL("some_link.jsp") %>">Some link</a>
> 
> Likewise, whenever the logic of your page indicates that a redirect is
> required, instead of calling:
>     response.sendRedirect("some_link.jsp");
> you call
>     response.sendRedirect(response.encodeRedirectURL("some_link.jsp"));
> 
> Check out the J2EE tutorial for examples:
> http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets11.html#63281
> 
> Chris.
> 




RE: The function for response.encodeURL....me still not sure

Posted by Anson Zeall <ze...@bigpond.net.au>.
Thanks a lot,

But......for example...if I have a jsp file..that includes another jsp
file in it.....how can I write it with encodeURL? Doesn't seem to work..

E.g.
<%@ include file="<%= response.encodeURL("header_status_register.jsp")
%>" %> doesn't work

Anson

-----Original Message-----
From: Christopher Williams [mailto:ccwilliams3@ntlworld.com]
Sent: Wednesday, September 10, 2003 5:55 PM
To: Tomcat Users List
Subject: Re: The function for response.encodeURL....me still not sure


As I said, the URL-rewriting is done by the container to allow you to
use HTTP sessions when the user of your site has disabled cookies and it
does this by appending ";jessionid=blah-blah-blah" to end of your URLs
prior to the query string ("?blah=stuff&jabber=yakka-yakka...").  This
is all in the servlet spec.  However, you need to give the container the
opportunity to do so and for this you need to use the encodeURL methods
of HttpServletResponse.

Think about your JSPs.  Currently (presumably) you have links like the
following:
    <a href="some_link.jsp">Some link</a>

To enable session tracking without cookies, all you need to do is:
    <a href="<%= response.encodeURL("some_link.jsp") %>">Some link</a>

Likewise, whenever the logic of your page indicates that a redirect is
required, instead of calling:
    response.sendRedirect("some_link.jsp");
you call
    response.sendRedirect(response.encodeRedirectURL("some_link.jsp"));

Check out the J2EE tutorial for examples:
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets11.html#63281

Chris.

----- Original Message -----
From: "Anson Zeall" <ze...@bigpond.net.au>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, September 10, 2003 2:56 AM
Subject: The function for response.encodeURL....me still not sure


> Hi guys,
>
>     I was asking about the login stuff before from previous emails and

> trying to avoid the use of cookies. Someone in the group asked me to
> try
and
> use sessions ...using response.encodeURL and stuff. Can someone
> explain a bit more what that does, or is there a site that can explain

> to me about that?
>
>
>
> Thanks,
>
> Anson
>
>


------------------------------------------------------------------------
----
----


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




Re: The function for response.encodeURL....me still not sure

Posted by Christopher Williams <cc...@ntlworld.com>.
As I said, the URL-rewriting is done by the container to allow you to use
HTTP sessions when the user of your site has disabled cookies and it does
this by appending ";jessionid=blah-blah-blah" to end of your URLs prior to
the query string ("?blah=stuff&jabber=yakka-yakka...").  This is all in the
servlet spec.  However, you need to give the container the opportunity to do
so and for this you need to use the encodeURL methods of
HttpServletResponse.

Think about your JSPs.  Currently (presumably) you have links like the
following:
    <a href="some_link.jsp">Some link</a>

To enable session tracking without cookies, all you need to do is:
    <a href="<%= response.encodeURL("some_link.jsp") %>">Some link</a>

Likewise, whenever the logic of your page indicates that a redirect is
required, instead of calling:
    response.sendRedirect("some_link.jsp");
you call
    response.sendRedirect(response.encodeRedirectURL("some_link.jsp"));

Check out the J2EE tutorial for examples:
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets11.html#63281

Chris.

----- Original Message ----- 
From: "Anson Zeall" <ze...@bigpond.net.au>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, September 10, 2003 2:56 AM
Subject: The function for response.encodeURL....me still not sure


> Hi guys,
>
>     I was asking about the login stuff before from previous emails and
> trying to avoid the use of cookies. Someone in the group asked me to try
and
> use sessions ...using response.encodeURL and stuff. Can someone explain a
> bit more what that does, or is there a site that can explain to me about
> that?
>
>
>
> Thanks,
>
> Anson
>
>


----------------------------------------------------------------------------
----


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org