Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a simple html page filter.

 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Heonkoo Lee
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic