• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URL mapping problem: www.website.com/anyUser to bring up details of that specific user using post

 
Dan Arboscelli
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have looked for quite a bit about this but couldn't find any relevant solutions, so posting here.

I am creating an application that allows users to register so that they can share a personal page online.

I would like to have a page that lists the data visible to all accessible by anyone who just types in the corresponding url.

Is there anyway that I can get the personalised URL to have this structure:

www.website.com/firstUser
www.website.com/secondUser
www.website.com/thirdUser

and so on?

I tried to intercept a 404 error because the page for that link doesn't actually exist on the server, and use the URL to find out which user needs to be selected.
Problem is, when the request reaches the error page, the url associated to the request is already /errorPage and I lose the original URL.
Does anybody have any idea how to achieve this? I am pretty sure I have seen it somewhere.
Suggestions or links to solutions much appreciated

Also, mapping a custom extension would actually be good enough too.
But if go down that route with

<url-pattern>/*.abc</url-pattern>

I get this when starting tomcat:

java.lang.IllegalArgumentException: Invalid <url-pattern> /*.abc in servlet mapping

Hopefully I managed to explain the problem quite clearly.
Thanks, Dan
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your URLs should follow a more RESTful best practice pattern of something like:

www.website.com/users/firstUser

or something along those lines.

That's not only more conventional, it's easy to map to a servlet.
 
Dan Arboscelli
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the quick reply,
that was the temporary solution I had thought of without realising it was best practice already.
I will stick to that then!


Bear Bibeault wrote:Your URLs should follow a more RESTful best practice pattern of something like:

www.website.com/users/firstUser

or something along those lines.

That's not only more conventional, it's easy to map to a servlet.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it makes sense to convert these to API calls, you might be interested in the jersey RESTFul web service server

http://jersey.java.net/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic