wood burning stoves
The moose likes Struts and the fly likes Struts URL tag issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts URL tag issue" Watch "Struts URL tag issue" New topic

Struts URL tag issue

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10003


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!

[Thumbnail for screenshot_html.png]

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10003

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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Struts URL tag issue
It's not a secret anymore!