• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting the server path

 
Steve Ashton
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Giving a quick glance to the api, it looks like replacing getRealPath with getResource might do the trick.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!