Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Permalinks with JSP

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Peter Bergoff
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 26947
83
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Investigate the methods of HttpServletRequest -- what you seek is there.

(Hint: the magic word is path.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic