aspose file tools*
The moose likes JSP and the fly likes How to display a page without the trailing .jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to display a page without the trailing .jsp" Watch "How to display a page without the trailing .jsp" New topic
Author

How to display a page without the trailing .jsp

Predrag Stojadinovic
Greenhorn

Joined: Nov 18, 2008
Posts: 15
I will make this short. I believe there is a way to do this but for the life of my I can't find it anywhere

Instead of:
www.some-site.com/welcome.jsp

I would like to be able to simply use:
www.some-site.com/welcome

this would display the content of my welsome.jsp page but the address would not contain the .jsp extension.

Anyone has an idea how this is done? Or WHERE I can read about it?
[ December 18, 2008: Message edited by: Predrag Stojadinovic ]

http://stojadinovic.net
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Have you checked with configuring the web.xml file ?
I am sure there must be a way out.


Regards, Sud.
SCJP 5 ScjpFAQ JLS
Predrag Stojadinovic
Greenhorn

Joined: Nov 18, 2008
Posts: 15
The problem is that I don't have a clue how to put this in proper wording in order to google it or something
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

We know jsp is a servlet.
So it too can be configured as a servlet can be.
I am giving you an example on how to configure the jsp.

You can register a JSP as a servlet using the <servlet> tag. In this example a URL containing /main will invoke myJSPfile.jsp:

<servlet>
<servlet-name>myFoo</servlet-name>
<jsp-file>myJSPfile.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>myFoo</servlet-name>
<url-pattern>/main</url-pattern>
</servlet-mapping>


Registering a JSP in this manner allows you to specify the load order, initialization parameters, and security roles for a JSP, just as you would for a servlet.

Hope this helps.

Thank you.
[ December 18, 2008: Message edited by: Sudipto Shekhar ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
www.some-site.com/welcome

This would be a URL that goes to a Java servlet. The servlet would then forward control to the JSP page, e.g. welcome.jsp
Predrag Stojadinovic
Greenhorn

Joined: Nov 18, 2008
Posts: 15
Thanks, I will try with wild cards but I doubt that something like this would work:


[ December 18, 2008: Message edited by: Predrag Stojadinovic ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

No, do not try to do this with a wildcard mapping. That way lies pain.

Rather follow the excellent advice to write your app as it it were 2008 and use page controllers to field requests that then forward to the views.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Predrag Stojadinovic
Greenhorn

Joined: Nov 18, 2008
Posts: 15
Oook, I see you're the man to listen to
I actually have "Prototype and Scriptaculous in Action" on my shelf

Anywho, I won't ask you for a code example, but some reading links would be appreciated. Hell, if its in one of your books just tell me which one, my MasterCard is right next to me!

But let me just take a guess from your comment: I forward all page calls to one jsp||servlet and in it I take what the user wanted from request.getRequestURI(), append the ".jsp" to it and use RequestDispatchers forward method?



But before I do any of it I'm gonna read this through.

[ December 18, 2008: Message edited by: Predrag Stojadinovic ]
[ December 18, 2008: Message edited by: Predrag Stojadinovic ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Originally posted by Predrag Stojadinovic:
But before I do any of it I'm gonna read this through.

That article is exactly what I was about to recommend.

It should give you a good feel for the modern state of web application structure best practices, where page controllers handle the setup for JSP pages, and the JSPs themselves are simple ("dumb") view components that use JSTL and EL in favor of old-fashioned scriptlets.
Predrag Stojadinovic
Greenhorn

Joined: Nov 18, 2008
Posts: 15
I read, I tried, I failed miserably...




Help
[ December 18, 2008: Message edited by: Predrag Stojadinovic ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Go download the Struts libraries and read a tutorial or two. This should get you started on learning the Model-View-Controller design pattern. Once you learn this, you could then branch out and possibly start coding your own stuff.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Or check out my Front Man front controller implementation. Struts is a beast.
Predrag Stojadinovic
Greenhorn

Joined: Nov 18, 2008
Posts: 15
Originally posted by Bear Bibeault:
Or check out my Front Man front controller implementation. Struts is a beast.

- I already saw the Front Man and wrote down to check it out asap

Originally posted by James Clark:
...you could then branch out and possibly start coding your own stuff.

- Yo James, I'm not quite sure what you mean by "start coding your own stuff"?
I'm no Bear B. but c'mon, "start"?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Based upon the code that you posted, it certainly looks like you are attempting (aka starting) to write a Controller. This would be a good programming exercise, if you have the time and are interested in the details of how you would design a Controller. However, FrontMan is already written and the Struts Controller is already written. Take your pick )
[ December 18, 2008: Message edited by: James Clark ]
Venki Ananth
Ranch Hand

Joined: Dec 17, 2008
Posts: 32
Hi,

Create a new servlet "wecome and then do redirect to "welcome.jsp"

Else "welcome.jsp" will have its own servlet so do mapping in "web.xml" like this,
<servlet>
<servlet-name>wecome</servlet-name>
<jsp-file>welcome.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>welcome</servlet-name>
<url-pattern>welcome</url-pattern>
</servlet-mapping>
[ December 18, 2008: Message edited by: Venki R ]

Venki
http://saalram.com
Predrag Stojadinovic
Greenhorn

Joined: Nov 18, 2008
Posts: 15
Originally posted by James Clark:
Based upon the code that you posted, it certainly looks like you are attempting (aka starting) to write a Controller.

True that...

Well, it's better to use the wheel than to re-invent it, right? And since the FrontMan is seriously lighter than Struts... easy pick...

On the other hand, a friend of mine just suggested a filter instead of the Controller?

Like:


I will try this tonight when I get home from work. And if this fails I will use the FrontMan.
[ December 19, 2008: Message edited by: Predrag Stojadinovic ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

I don't like using filters as a controller, rather I use them as filters, and use controllers as controllers. Sorta like using an ice pick to clean your teeth. It can work, but...
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
lol
 
Consider Paul's rocket mass heater.
 
subject: How to display a page without the trailing .jsp