• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Servlet virtual path

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Is there a way to get a servlet to accept a path and forward this to a particular JSP page? I'm new to servlets.

So, something like this:

www.mywebsite.com/myproject

forwards to

www.mywebsite.com/workspaces/login.jsp?workspaceid=someidformyproject

The directory myproject would not exist but would be a simplified URL.

Basically, I want to create a system that allows users to create project workspaces similar to SharePoint - so they specify the name of the workspace and this automatically becomes a directory path on the server (though the directory will not actually exist).

I hope that makes sense - any help is very much appreciated.

Cheers,

Steve
 
Sheriff
Posts: 67590
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
Of course. Declare a servlet mapping for the servlet and the use a request dispatcher to forward to the JSP.
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,

When you say delare a servlet mapping, is that in the web.xml? If you could give me an example, that would be really helpful as I'm really new to this - I'm one of those annoying JSP developers that doesn't understand servlets (just knows they're there).

Do I need to declare a servlet mapping for every directory or can I do something like:

/workspaces (goes to the servlet)
/workspaces/myproject (servlet picks up the myproject as a parameter)

As you can see, I need some guidance!

Thanks for your help.

Steve
 
Bear Bibeault
Sheriff
Posts: 67590
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

Originally posted by Steve Wood:

When you say delare a servlet mapping, is that in the web.xml? If you could give me an example..

Yes.

Here's a simple sample:



After that, every URL mapped to your web app context that begins with /whatever/ will map to the servlet. The remainder of the URL is available from the request instance via getPathInfo().

I'm one of those annoying JSP developers that doesn't understand servlets (just knows they're there).



I highly recommend you wrap your mind around servlets. The best web app structures embrace both servlets and JSP, each to their best advantage. Grab a copy of the Servlet Spec and read it cover to cover. It's a surprisingly easy read.

Link to Spec can be found in the JSP FAQ.

Do I need to declare a servlet mapping for every directory or can I do something like:

/workspaces (goes to the servlet)
/workspaces/myproject (servlet picks up the myproject as a parameter)



See above.

As you can see, I need some guidance!



You're in the right place.

Thanks for your help.



My pleasure.
[ February 09, 2007: Message edited by: Bear Bibeault ]
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,

I'm up and running. I'll definitely be reading about servlets - I'm now at a stage where I really need to understand how they work. This is the first time I've thought "hmmmm... maybe a servlet could do that" - I'm sure they can do a lot more!

Cheers,

Steve
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a link to the servlet spec in my signature.
There is no better reference.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic