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 Creating a simple html page filter. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Creating a simple html page filter." Watch "Creating a simple html page filter." New topic
Author

Creating a simple html page filter.

Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
I've used servlet filters in the past with J2EE apps, but I was wondering if there is anything preventing the same thing from being done on a simple HTML based application.

Assuming the web server supports an up to date servlet spec (and it does...it is the one bundled in the Sun Java App Server 8.1), can you simply add the directories and files you need to get the servlet filter to work, or is there something "special" that might need to be done?

What is there today just looks like this:



What I plan to do is make it look like this:




Will that work? In other words, will the web server know to look at the web.xml file under the WEB-INF directory in this sort of structure, or is something else needed?

Thanks!
[ September 28, 2005: Message edited by: Darrin Smith ]
Heonkoo Lee
Ranch Hand

Joined: Feb 10, 2005
Posts: 85
Originally posted by Darrin Smith:

What I plan to do is make it look like this:



Will that work? In other words, will the web server know to look at the web.xml file under the WEB-INF directory in this sort of structure, or is something else needed?


I don't think it will work. WEB-INF directory must be under the context root of a web application. If you want to apply your filter to all the subdir[number], you need to create a web app context root directory under docroot of your server like this:



And you just need to add any necessary filter mappings in the web.xml. Hope this helps.
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
Originally posted by Heonkoo Lee:


Will that work? In other words, will the web server know to look at the web.xml file under the WEB-INF directory in this sort of structure, or is something else needed?
<hr></blockquote>

I don't think it will work. WEB-INF directory must be under the context root of a web application. If you want to apply your filter to all the subdir[number], you need to create a web app context root directory under docroot of your server like this:



And you just need to add any necessary filter mappings in the web.xml. Hope this helps.[/QB]



Thanks for the feedback.

I was thinking that if this were the ROOT web application then you wouldn't need any context-root. In this case, it is the only application there, but I guess adding a context root above the subdirs is the way to go anyway (I didn't write this originally).

The important thing is that the filter servlet will work with this sort of structure, which is what I was thinking, but wasn't sure of.

Thanks again.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

I don't think it will work. WEB-INF directory must be under the context root of a web application.


The folder containing the WEB-INF folder is the context root of a web application.

All you need to do is define the context in your container's config file. For Tomcat, that would be the config/server.xml file.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Heonkoo Lee
Ranch Hand

Joined: Feb 10, 2005
Posts: 85
Thanks for pointing out you can do that at a container level. I was talking about the web application level in a standard way without modifying server config files.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

P.S. Tomcat 5 also has a new-fangled way of adding contexts without changing server.xml by dropping xml fragments into the right config folder. I haven't had chance to play with it much so the details escape me at the moment -- check out the Tomcat forum which I know has addressed this if interested.
 
Consider Paul's rocket mass heater.
 
subject: Creating a simple html page filter.