File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes URL mapping problem: www.website.com/anyUser to bring up details of that specific user using post Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "URL mapping problem: www.website.com/anyUser to bring up details of that specific user using post" Watch "URL mapping problem: www.website.com/anyUser to bring up details of that specific user using post" New topic
Author

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

Dan Arboscelli
Greenhorn

Joined: Jan 26, 2011
Posts: 2
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

Joined: Jan 10, 2002
Posts: 60048
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dan Arboscelli
Greenhorn

Joined: Jan 26, 2011
Posts: 2
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

Joined: Feb 24, 2006
Posts: 6657
    
    5

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/


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URL mapping problem: www.website.com/anyUser to bring up details of that specific user using post
 
Similar Threads
RequestDispatcher not working properly in Websphere
storing multiple attributes for one entity
Page history
problem with using URIs as parameters
Redirect requests for *.jsp to *.jsf?