Vinay,

You've almost got it down....  The URLEncoder methods in java.net are
supplied for exactly the purpose that you used them for - in order to
transform strings to x-www-form-urlencoded MIME format.  The
HttpServletResponse object has two methods which have a similar name but
actually perform an entirely different function....

        response.encodeURL - modifies a URL to be displayed to the user
                                   so that the correct session can be retreived
                                   if the link is chose.
        response.encodeRedirectURL - does the same thing except for URLs used
                                             for redirection.

If you are trying to redirect while saving session information, then you
want to use the second method:

response.sendRedirect(response.encodeRedirectUrl(java.net.URLEncoder.encode(
sURL)));

If you just want to redirect and could care less about session information,
then simply
skip the step encoding the URL with the response altogether:
        response.sendRedirect(java.net.URLEncoder.encode(sURL));

This might do the trick!
-AMT

> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Vinay K.V. Menon
> Sent: Tuesday, June 20, 2000 3:31 AM
> To: [EMAIL PROTECTED]
> Subject: Passing spaces in query strings
>
>
> Hi all!
>         I am having a problem passing parameters with spaces in
> the middle to
> servlets.
>         I tried encodeUrl but it does not seem to encode the
> spaces with +'s. So I
> looked up the archive and found that I could use the URLEncoder.encode
> method. Well, this method seems to be working fine as far as
> converting the
> spaces to +'s go but when I try to do an encodeUrl of that string and a
> sendRedirect it seems to be failing. Here is what I am trying to do,
>
> response.sendRedirect(response.encodeUrl(java.net.URLEncoder.encod
> e(sURL)));
>
> And for one of the cases with spaces here is what I get,
>
> 500 Internal Server Error
>
> The servlet named invoker at the requested URL
>
>
> http://localhost/servlet/polyx.application.FileDeleteServlet?AREAI
> D=A1&DOCUM
> ENTID=4&FILENAME=Article+Writer+Functional+Specifications.doc
>
> reported this exception
>
> polyx.application.FileDeleteServlet?AREAID=A1&DOCUMENTID=4&FILENAM
> E=Article+
> Writer+Functional+Specifications.doc:
>
> polyx.application.FileDeleteServlet?AREAID=A1&DOCUMENTID=4&FILENAM
> E=Article+
> Writer+Functional+Specifications.doc. Please report this to the
> administrator of the web server
>
> when I click the URL[above url that comes in the error message] in the
> browser it works! Can somebody tell me how to go anbout handling spaces?
>
>         IE seems to encode the URL directly without the use of
> the URLEncoder but
> including the URLEncoder.encode methid it does not work in IE either.
>
> Thanks and advance
>
> Vinay
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to