Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

changing relative urls back to full urls  RSS feed

 
Brendan Kennedy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I'm making this servlet that one would use to browse the web through. It
parses the html at a given url so as that all links point back to it as
follows:
<a href="http://somehosthost">link</a>
becomes
<a href="http://myhost:8080/student/servlet/myserv?url=http://somehosthost">
link</a>
by problem is relative urls within the page like <a href="mypage.html">
because there is no way to directly read this from my servlet. I could just
keep the hostname in my session context or something, but then what if the
relative url is from a page at
http://somehosthost/thisdir/thatdir/thepage.html ? I'll end up looking for it
in the base directory.
Anyways, i figure someone out there's done this before
Any help is greatly appreciated,
thanks in advance,
Brendan
 
Brendan Kennedy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I've figured it out. All relative links on the page are relative to
the url of the page, so all I need is to get the current url up till the last /
and add the relative url, unless the relative url starts with a / , in which
case I just use the hostname. I so hate string manipulation though :/
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!