File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Mapping *.jsp to *.html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Mapping *.jsp to *.html" Watch "Mapping *.jsp to *.html" New topic
Author

Mapping *.jsp to *.html

Arron Ferguson
Greenhorn

Joined: Feb 01, 2005
Posts: 28
I'm not entirely sure how to make all requests to JSPs map directly to the HTML extension. For example, invoking index.jsp by only allowing the user to type index.html. If the user types "index.jsp" giving a 404 error instead.

Any help most appreciated.

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You could create a servlet entry with mapping for each jsp page in your web.xml.




To keep them from typing '*.jsp' in directly, you could put your actual JSP pages under WEB-INF or use a filter that looks for '.jsp' at the end of the URI. You could also put them in a directory and create a mapping for that directory that sends them to your 404 page.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Arron Ferguson
Greenhorn

Joined: Feb 01, 2005
Posts: 28
Ben Souther,

Thanks for your reply. I guess I'm trying to find a "silver bullet" since my web app creates JSP files dynamically. I suppose what I can do is get one of the servlets to add any new JSPs that have been created to the web.xml file (along with its url-mapping).

Thanks again.

Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
You could also create a Servlet or JSP onto which EVERYTHING maps. You would then inside this Servlet / JSP forward the request onto whichever page they specified in the URL!


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Arron Ferguson
Greenhorn

Joined: Feb 01, 2005
Posts: 28
Tim Baker wrote:
You could also create a Servlet or JSP onto which EVERYTHING maps. You would then inside this Servlet / JSP forward the request onto whichever page they specified in the URL!


Heheh, you know, right after reading this, I started looking at examples and the light went on after reading:

http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters-p2.html

And I came to the same conclusion.



Great minds think alike?

Arron Ferguson
Greenhorn

Joined: Feb 01, 2005
Posts: 28
Based on Tim Baker's good idea, I came up with a Servlet that asks a Java class for a list (Vector) of names of HTML documents that are considered 'valid' (i.e. map 1:1 to JSP files). It then uses those names to map to the JSP (without the user knowing) and redirects to that JSP. If a user types in the name of an html document that does not exist (i.e. 404), I redirect to the 404 servlet. Since people here shared their time in answering, it's only fair I share the code (not that it's spectacular or anything):



The following entry must also be in the Web app's web.xml:



Enjoy.



[ February 04, 2005: Message edited by: Arron Ferguson ]
[ February 04, 2005: Message edited by: Arron Ferguson ]
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
cool
Arron Ferguson
Greenhorn

Joined: Feb 01, 2005
Posts: 28
Actually,

the following line:



Should be replaced with:



Otherwise the user can type:

adsflasdfasdfindex.html

instead of index.html and it would still work.

I always seem to find these *after* I've submitted. :roll:

But it works now - I tried it.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410


I always seem to find these *after* I've submitted.


You can edit your posts after you submit them.
Just click on the notepad/pencil icon.
[ February 04, 2005: Message edited by: Ben Souther ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mapping *.jsp to *.html