Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:12

Problem with '&' in a URL string

Poster: schnocky
Dated: Monday August 30 2004 - 19:49:48 BST

I have read through another lengthy dialog on this issue (Can't get link with '&' to work), but the solution doesn't seem to work for me.

I am dynamically generating content for the menu using data from the database (JavaServer Pages and JSTL). I have a JSP that I create which contains several request parameters (SEPARATED BY &) ... arm3=bleah

This appears on the page as: ... arm3=bleah

which promptly has the URL truncated to:

which loses any request parameter after the first one.

I have tried replacing '&' with '%26' in the string (doesn't work). I believe that it is the output of the <c:out> JSTL tag that is converting the '&' character to '&amp;', but that it is the menu code that is truncating the URL when it encounters the semicolon.

Thanks for any help on this problem.


Poster: Andy
Dated: Monday August 30 2004 - 19:56:42 BST


This is where backquotes come into the equation.

Because the menu relies on both semi-colons and the equals sign for it's text manipulation, the menu has trouble knowing that the text ;parm2=foo3&amp;parm3=bleah is part of the url.

All you need to do is tell it to leave it alone and it will. This is done by enclosing the url inside backquotes. Backquotes are the little reversed single quote character. On my UK keyboard it is next to the number 1 on the top row but could be somewhere else on other International keyboards.

Anyway, here's how you should include the aI() string:


Hope this helps

Poster: schnocky
Dated: Monday August 30 2004 - 20:13:10 BST

OK, sounds good. Right now I only have relative URLs, will they work?

I have an output of

aI("text= Other;url='/bar/reports/startpage.jsp?p1=2&amp;p2=404;");

and the menus don't show up.


Poster: perldev
Dated: Monday August 30 2004 - 21:20:33 BST

Try this out:


Poster: John
Dated: Tuesday August 31 2004 - 15:06:23 BST

schnocky wrote:
I have an output of

aI("text= Other;url='/bar/reports/startpage.jsp?p1=2&amp;p2=404;");

and the menus don't show up.

Looks like you're using a regular quote there rather than a backquote, and it's not closed anyway.

aI("text= Other;url=`/bar/reports/startpage.jsp?p1=2&amp;p2=404`;");

Poster: schnocky
Dated: Tuesday August 31 2004 - 18:11:47 BST

Thanks for the suggestions, I finally found a combination that will work.

Here are my observations.

I did use the backquote character '`' to surround the URL. This works as long as you have a fully qualified URL. When I added it to a relative URL, the menus did not show up.

I also tried the suggestion by perldev, but the JSP processor converts the output to

"/abc/page.jsp?foo=1" + "&amp;bar=2"

(e.g. translates '&' to "&amp;" for me)

Poster: schnocky
Dated: Tuesday August 31 2004 - 19:45:07 BST

OK, it took one more iteration to solve my problem. It seems that the issue was the JSP engine replacing '&' with "&amp;" that was the root cause of the problem. The solution was to modify the JSP page and have the '&' explicitly on the page while using the JSP engine to generate the rest of the string. Then, the menu code didn't have an additional semicolon to contend with and things were quite happy and tranquil. My code does something like this

For the example string attribute 'outputString of my class,


I was using

aI("<c:out value='${theItem.outputString}'/>");

which resulted in


which was parsed as /main/foo/bar.asp?parm1=it&amp

While adding backquotes enabled the menus to be displayed (and retain the entire URL string), clicking on the link resulted in the loss of all request parameters (the "&amp;" in the string screwed that up.

I now use the following code to create the output

<c:forEach items='${menu.menuItem}' var='theItem'>
<c:set var='accessibleItem' value='${theItem}' scope='request'/>
<% String s = ((DhtmlMenuItemData) request.getAttribute("accessibleItem")).getOutputString();
int strpos = s.indexOf("&");
while (strpos > 0) {
out.write(s.substring(0, strpos - 1));%>&<%
s = s.substring(strpos, s.length()-1);
strpos = s.indexOf("&");
out.write(s + "\");");

Thanks for the suggestions.