Author
Struts URL tag issue
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
Guys,
I have a strange issue with using s:url tags to call an action. Below is what I have on one of my jsp page:
When I click the link, I get the following as exception:
When I viewed the rendered html using Mozilla's firebug, I see the following rendered for the anchor tag as shown in the screenshot
How could this be possible then? Bemused!
screenshot_html.png
SCJP 1.4, SCWCD 1.4 - Hints for you , SCBCD Hints - Demnachst , SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
OK. Managed to get rid of it. Changed the anchor tag to <a href="<%=request.getContextPath()%>/content/meetUp.action">here....
But why would the s:url not work? And what is the deal with the request.getContextPath()? Do I need to prepend it to all my url links in my app?
Richard Golebiowski
Ranch Hand
Joined: May 05, 2010
Posts: 213
It should work, unless it's not in the"/" namespace.
Jesus Mireles
Ranch Hand
Joined: Mar 10, 2010
Posts: 122
From your screenshot it looks like its not even rendering html .. its just sptting out what you typed in the jsp ... so I would question if you have the s prefix defined in your jsp.
<%@ taglib prefix="s" uri="/struts-tags" %>
From your comment it looks like you changed it to scriptlet code to get the context path and then the namespace .... it looks like if you had your prefix defined correctly then I'm guessing you can probably do this:
<s:url var="url" action="meetUp" namespace="content"/>
<s:a href="%{url}">here ...</s:a>
Because from your comment it looks like this action is in the content namespace and not the / which would be the default.
subject: Struts URL tag issue