permaculture playing cards*
The moose likes Struts and the fly likes Getting the server path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting the server path" Watch "Getting the server path" New topic
Author

Getting the server path

Steve Ashton
Greenhorn

Joined: Sep 04, 2002
Posts: 5
Hi,

I am using Struts for my application and I used to have a hyperlink in my JSP page. The link was like this <a href="<html:rewrite page="/assets/css/public.css" />">The Link</a>

However, I moved all this code into a custom taglib and when I write the code in the taglib, when it prints it out to the JSP page, it doesn't rewrite the url, it actually writes <html:rewrite page="/assets/css/public.css" /> which obviously is not what I want.

I tried a number of things such as

pageContext.getServletContext().getRealPath("/assets/images/plus.gif")

but this just gets the path on the C:/ drive which is not right. Can anyone let me know how I can return the server path to the right directory.

Many thanks
Steve Ashton
Greenhorn

Joined: Sep 04, 2002
Posts: 5
I found the solution to this so I thought I would post it incase anyone ever comes across the same problem.

RequestUtils.absoluteURL(req,"/assets/images/plus.gif")
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Giving a quick glance to the api, it looks like replacing getRealPath with getResource might do the trick.


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting the server path