Two Laptop Bag*
The moose likes JSP and the fly likes Permalinks with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Permalinks with JSP" Watch "Permalinks with JSP" New topic
Author

Permalinks with JSP

Peter Bergoff
Ranch Hand

Joined: Apr 07, 2004
Posts: 103
Hi everyone,

I'm wondering how I can do wordpress type permalinks in Java (or specifically JSP). For example:
http://www.homes.com/styles.jsp?type=brick
to
http://www.homes.com/brick
or
http://www.homes.com/styles/brick (where styles signals which JSP needs to be called)
or something like that to avoid the parameters.

Ideally this would be dynamic so I wouldn't have to set up individual permalinks for each page.

Thanks!

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60817
    
  65

Sure, you'd just add the proper mappings to the deployment descriptor.

But... a servlet would be a better target; JSPs are rarely the target of a URL -- the servlet controller should handle any processing before forwarding to a JSP to render the view.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Bergoff
Ranch Hand

Joined: Apr 07, 2004
Posts: 103
Thanks Bear! I am familiar with mapping to shorten and change servlet names. Is there a way to take this a step further and use the mapping to avoid placing parameters in the URL when calling that servlet?
Something like:
http://www.homes.com/styles-brick
instead of
http://www.homes.com/styles?type=brick

Basically I want to make my URLs pretty without having to create a new servlet for each page. I suppose in theory I could create a unique servlet for each variation but it would be nice to avoid that. Is there a standard for this type of thing?

Thanks!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't know about a "standard", but it's more traditional to do http://www.homes.com/styles/brick than http://www.homes.com/styles-brick. In other words, if there's a hierarchy then make it look like one, with the slashes separating level names.

And sure, there isn't anything stopping you from mapping a variety of URLs to a single servlet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60817
    
  65

Investigate the methods of HttpServletRequest -- what you seek is there.

(Hint: the magic word is path.)
 
 
subject: Permalinks with JSP
 
Similar Threads
Stock up on JSP 404 error. JSP could not be located.
foreach not working in scriptlet
Typecasting problem, dont understand why!
Bugs Bunny - A Racist Rabbit?
How to submit a form from a como box - with enter key