Khoo Swee Chin wrote:
>
> Hi
> I need help on this one. My response.encodeURL not working. Here are my
> codes, what did i do wrong this time?
>
> ....
> <BODY BGCOLOR="#FFFFFF">
> <% String link="cuba2.jsp?Name=Khoo Swee Chin";%>
> <A HREF="<%=response.encodeURL(link)%>"><%=link%></A>
> </BODY>
> ...
>
> When i try to display Name parameter i only get Khoo, where are the rest??
> Please help. :)
The name encodeURL() is actually a bit misleading, since this method
is used for "URL rewriting" (adding session ID info to a URL) as opposed
to "URL encoding" (encoding special characters in URL parameters).
If you want both URL encoding and URL rewriting, you need to do something
like this:
<%
String link="cuba2.jsp?Name=" +
java.net.URLEncoder.encode("Khoo Swee Chin");
%>
<A HREF="<%=response.encodeURL(link)%>"><%=link%></A>
In your example using the URLEncoder is overkill, since it's a static
parameter value that can as easily be encoded manually:
<% String link="cuba2.jsp?Name=Khoo+Swee+Chin"; %>
<A HREF="<%=response.encodeURL(link)%>"><%=link%></A>
If the parameter value is actually a variable, using the URLEncoder
makes more sense.
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
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