You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@beehive.apache.org by Jeremiah Johnson <je...@bea.com> on 2006/07/12 08:25:39 UTC

curious behavior with href that contains a %

My observation is that href in netui:anchor and at least one of the
netui-data tags is specifically 'encoding' the % if it appears.  It
seems to me that either the value in href should be fully encoded or the
% should be left as is.

Here is an attempt at a simplified example:
--- clip from Controller.java
	@Jpf.Action(forwards = { @Jpf.Forward(name = "success", path =
"index.jsp") })
	protected Forward begin() {
		getRequest().setAttribute("reserved",
"plus+divide/equal=quote'percent%semicolon;question?colon:at@and&doller$
comma,");
		getRequest().setAttribute("encoded",
URLCodec.encode("plus+divide/equal=quote'percent%semicolon;question?colo
n:at@and&doller$comma,"));
		return new Forward("success");
	}
---

I take that reserved stuff and put that in a netui:label and
netui:anchor and see that it is altered in the netui:anchor.

--- clip from index.jsp
<netui:body>
	<p><netui:anchor href="${reserved}">
		<netui:label value="${reserved}" />
	</netui:anchor></p>
	<p><netui:label value="${encoded}" /></p>
</netui:body>
---

So the value of href in the page rendered to the browser is
http://localhost:7001/aWar/plus+divide/equal=quote'percent%25semicolon;q
uestion?colon:at@and&doller$comma,

I expected either the same result as what is in one of the labels, but
only the % is changed.  Is this a bug or am I doing something wrong or
have incorrect expectations?

Thank you.

- jeremiah
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

Re: curious behavior with href that contains a %

Posted by Carlin Rogers <ca...@gmail.com>.
Hi Jeremiah,

Yes, as you've noted, the call to URLCodec.encode() is definitely different
than what is being done to encode the href for the <netui:anchor> tag. Your
updated example and explanation about using the parameter tag is correct.
Here's additional implementation details that might also help.

URLCodec.encode() does not look at all the parts of a URI (scheme, server,
path, query, etc described in the spec for generic syntax of URI -
http://www.ietf.org/rfc/rfc2396.txt ). It just implements the
'www-form-urlencoded' encoding scheme which is really specific for the form
where the name value pairs are escaped with + for space and %HH for ASCII
code of the characters that must be escaped in the query component of the
URI.

In the <netui:anchor> tag, a MutableURI class utilizes the
java.net.URIclass to encode the URI. The href attribute of the tag is
parsed into the
components and the java.net.URI class encodes according to RFC 2396 (at
least that's what the javadoc on URI states).

In this example, the href attribute of the tag will be parsed as
path = plus+divide/equal=quote'percent%semicolon;question

query = colon:at@and&doller$comma,

where there are two parameters separated by the '&' character. The
java.net.URI implementation encodes the % in the path and then when the URI
is rendered to the page the '&' is just written out as the "&amp;" entity.

As you already described in your followup example, you can control some of
the encoding by using the <netui:parameter> tag along with the <netui:anchor
href="">.

Also, if you have ecoded URIs and encoded parameters that you want to pass
to the tags in the pages of your application, you can configure NetUI for
your app to override the default behavior of encoding the urls for tags with
href attributes so that already encoded urls will not be re-encoded. Your
beehive-netui-config.xml would include the entry
<url-encode-urls>true</url-encode-urls> in the <url-config> section.

Kind regards,
Carlin

On 7/12/06, Jeremiah Johnson <je...@bea.com> wrote:
>
> I see now that my example was pretty opaque - sorry about that.  The
> short answer to my own question is that I am misusing the anchor tag.
> To get the results that I was expecting, I need to move the stuff that I
> consider parameters to the real parameter tag:
>
> <netui:body>
>   <p><netui:anchor href="">
>     <netui:parameter name="" value="${reserved}"/>
>     <netui:label value="${reserved}" />
>   </netui:anchor></p>
>   <p><netui:label value="${encoded}" /></p>
> </netui:body>
>
> In my real case, I was building a link to another machine that included
> both a machine name and some parameters; by putting all of that into the
> href, I was getting the 'mixed' results.  I need to put just the path
> part into href and the parameters into the parameter tag and all will be
> well.
>
> Thank you.
>
> - jeremiah
>
> > -----Original Message-----
> > From: Jeremiah Johnson
> > Sent: Wednesday, July 12, 2006 12:26 AM
> > To: user@beehive.apache.org
> > Subject: curious behavior with href that contains a %
> >
> > My observation is that href in netui:anchor and at least one of the
> > netui-data tags is specifically 'encoding' the % if it appears.  It
> > seems to me that either the value in href should be fully encoded or
> the
> > % should be left as is.
> >
> > Here is an attempt at a simplified example:
> > --- clip from Controller.java
> >       @Jpf.Action(forwards = { @Jpf.Forward(name = "success", path =
> > "index.jsp") })
> >       protected Forward begin() {
> >               getRequest().setAttribute("reserved",
> >
> "plus+divide/equal=quote'percent%semicolon;question?colon:at@and&doller$
> > comma,");
> >               getRequest().setAttribute("encoded",
> >
> URLCodec.encode("plus+divide/equal=quote'percent%semicolon;question?colo
> > n:at@and&doller$comma,"));
> >               return new Forward("success");
> >       }
> > ---
> >
> > I take that reserved stuff and put that in a netui:label and
> > netui:anchor and see that it is altered in the netui:anchor.
> >
> > --- clip from index.jsp
> > <netui:body>
> >       <p><netui:anchor href="${reserved}">
> >               <netui:label value="${reserved}" />
> >       </netui:anchor></p>
> >       <p><netui:label value="${encoded}" /></p>
> > </netui:body>
> > ---
> >
> > So the value of href in the page rendered to the browser is
> >
> http://localhost:7001/aWar/plus+divide/equal=quote'percent%25semicolon;q
> > uestion?colon:at@and&doller$comma,
> >
> > I expected either the same result as what is in one of the labels, but
> > only the % is changed.  Is this a bug or am I doing something wrong or
> > have incorrect expectations?
> >
> > Thank you.
> >
> > - jeremiah
> _______________________________________________________________________
> Notice:  This email message, together with any attachments, may contain
> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> entities,  that may be confidential,  proprietary,  copyrighted  and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this
> by email and then delete it.
>

RE: curious behavior with href that contains a %

Posted by Jeremiah Johnson <je...@bea.com>.
I see now that my example was pretty opaque - sorry about that.  The
short answer to my own question is that I am misusing the anchor tag.
To get the results that I was expecting, I need to move the stuff that I
consider parameters to the real parameter tag:

<netui:body>
  <p><netui:anchor href="">
    <netui:parameter name="" value="${reserved}"/>
    <netui:label value="${reserved}" />
  </netui:anchor></p>
  <p><netui:label value="${encoded}" /></p>
</netui:body>

In my real case, I was building a link to another machine that included
both a machine name and some parameters; by putting all of that into the
href, I was getting the 'mixed' results.  I need to put just the path
part into href and the parameters into the parameter tag and all will be
well.

Thank you.

- jeremiah
 
> -----Original Message-----
> From: Jeremiah Johnson
> Sent: Wednesday, July 12, 2006 12:26 AM
> To: user@beehive.apache.org
> Subject: curious behavior with href that contains a %
> 
> My observation is that href in netui:anchor and at least one of the
> netui-data tags is specifically 'encoding' the % if it appears.  It
> seems to me that either the value in href should be fully encoded or
the
> % should be left as is.
> 
> Here is an attempt at a simplified example:
> --- clip from Controller.java
> 	@Jpf.Action(forwards = { @Jpf.Forward(name = "success", path =
> "index.jsp") })
> 	protected Forward begin() {
> 		getRequest().setAttribute("reserved",
>
"plus+divide/equal=quote'percent%semicolon;question?colon:at@and&doller$
> comma,");
> 		getRequest().setAttribute("encoded",
>
URLCodec.encode("plus+divide/equal=quote'percent%semicolon;question?colo
> n:at@and&doller$comma,"));
> 		return new Forward("success");
> 	}
> ---
> 
> I take that reserved stuff and put that in a netui:label and
> netui:anchor and see that it is altered in the netui:anchor.
> 
> --- clip from index.jsp
> <netui:body>
> 	<p><netui:anchor href="${reserved}">
> 		<netui:label value="${reserved}" />
> 	</netui:anchor></p>
> 	<p><netui:label value="${encoded}" /></p>
> </netui:body>
> ---
> 
> So the value of href in the page rendered to the browser is
>
http://localhost:7001/aWar/plus+divide/equal=quote'percent%25semicolon;q
> uestion?colon:at@and&doller$comma,
> 
> I expected either the same result as what is in one of the labels, but
> only the % is changed.  Is this a bug or am I doing something wrong or
> have incorrect expectations?
> 
> Thank you.
> 
> - jeremiah
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.