• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing URL  RSS feed

 
Andrew Hughes
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp that grabs a URL and inserts it into the session based upon the referring page. The url will be in a format similar to:

https://mysite.com/product.jsp?path=-1|3359|3362|3430&id=9962
https://mysite.com/product.jsp?path=-1|3359|3430&id=9962&promotion=CAT123
https://mysite.com/product.jsp?path=-1&id=9962

All I care about is the number after the final "id=" and before the & (if it exists at all). In this case 9962, but it could be 451 or 12587. Coming from a perl background, I would do this using a regex. However, since I am new to java/jsp, this is not obvious to me as to how to approach. Could anyone provide some direction?

Thanks so much.
 
Saritha Penumudi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the jsp you could use request.getParameter("id") which would return a String. If you want id to be some numeric then convert that String to Integer.

request is the implicit object for all JSP, hence you don't have to create this object explicitly.

Hope this helps

thank you
Saritha
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Saritha pointed out, you rarely need to do URL parsing on your own. When a URL is submitted to a page, the Servlet/JSP environment handles it for you in most circumstances.

However, it's not clear whether the URL you are concerned with is the current URL or not. COuld you be a little clearer on where the URL comes from? Is it the URL of the current page? Is it coming from somewhere else? If so, where?
[ November 01, 2004: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!