aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Is WEB-INF Directory mandatory ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Is WEB-INF Directory mandatory ? " Watch "Is WEB-INF Directory mandatory ? " New topic
Author

Is WEB-INF Directory mandatory ?

Somesh Rathi
Ranch Hand

Joined: Apr 27, 2006
Posts: 31
Hi Ranchers,
As I understand, JSP pages can execute without WEB-INF directory. Hence is it mandatory for WEb application to have WEB-INF directory ?

Thanks
Regards,
Somesh
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

If it is a web application, then it MUST have a web-inf directory. However you can test your JSPs and servlets directly in tomcat by placing them in the webapps directory (but then it will not be called a web application, it's just a jsp or servlet in that case)...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Originally posted by Ankit Garg:
If it is a web application, then it MUST have a web-inf directory. However you can test your JSPs and servlets directly in tomcat by placing them in the webapps directory (but then it will not be called a web application, it's just a jsp or servlet in that case)...


Ankit, you cannot test either servlet or jsp, without having a WEB-INF directory.
Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 460

Originally posted by Treimin Clark:


Ankit, you cannot test either servlet or jsp, without having a WEB-INF directory.


We can test jsps without WEB-INF directory. For web application we need WEB-INF to prevent any direct access to jsps and other resources. Moreover, we need to put our class files inside WEB-INF along with any other tag lib resources etc.

Having WEB-INF has many advantages like...

- If we have WEB-INF we have a web application.
- We can prevent direct access of resources.
- We can put custom tag definitions.
- We can have web.xml to control url patterns and server loading order.
- lot more...

Hope this helps.


Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Originally posted by Sai Surya:

We can test jsps without WEB-INF directory.


Hi Sai,

Can you explain that how can you run a JSP file, without having a WEB-INF directory (even empty) for your web app directory?
Christian Nicoll
Ranch Hand

Joined: Mar 09, 2008
Posts: 106
I tought also, that a WEB-INF directory is mandatory, but in the JavaRanch FAQ "Scwcd Hints" (Point 12) is the contrary listed:
http://faq.javaranch.com/view?ScwcdHints


SCJP 5, SCJD 5, SCWCD 5, SCBCD 5, SCJDWS 5
My SCBCD-Notes - My Hello World Webservice
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

The specification doesn't say that it is mandatory, but a web application without one looks like an apple pie without apples


[My Blog]
All roads lead to JavaRanch
Kathiresan Chinna
Ranch Hand

Joined: Aug 17, 2008
Posts: 115
Hi All,

Can anyone post the link that i can see the specfication ?

Thanks
Kathir
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

Originally posted by Kathir C:
Hi All,

Can anyone post the link that i can see the specfication ?


Take a look at the ScwcdLinks .


SCJP, SCWCD.
|Asking Good Questions|
Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 460

Originally posted by Treimin Clark:


Hi Sai,

Can you explain that how can you run a JSP file, without having a WEB-INF directory (even empty) for your web app directory?


Well, my tomcat installed at:
C:\apache-tomcat-5.5.26

my webapps directory at:
C:\apache-tomcat-5.5.26\webapps

so to test whether tomcat is running we usually do this:
http://localhost:8080/index.jsp

if you see the location of index.jsp, i guess its inside ROOT folder of webapps.

so to execute JSPs we don't have to have WEB-INF. For full fledged web application we need one.

I even tried to create empty folder (webapps/testing) inside webapps and created one test.jsp which will print the timestamp. (<%=new java.util.Date()%> . I still can access the test.jsp with following url without having any WEB-INF directory.

http://localhost:8080/testing/test.jsp

Correct me if I am wrong!
[ December 10, 2008: Message edited by: Sai Surya ]
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

Originally posted by Sai Surya:


I even tried to create empty folder (webapps/testing) inside webapps and created one test.jsp which will print the timestamp. (<%=new java.util.Date()%> . I still can access the test.jsp with following url without having any WEB-INF directory.
http://localhost:8080/testing/test.jsp

Correct me if I am wrong!


Yes you can. But that's not a full fledged Web application isn't it.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Originally posted by Sai Surya:

if you see the location of index.jsp, i guess its inside ROOT folder of webapps.

so to execute JSPs we don't have to have WEB-INF. For full fledged web application we need one.


Didn't you see that the ROOT folder has a WEB-INF directory itself?


Originally posted by Sai Surya:

I even tried to create empty folder (webapps/testing) inside webapps and created one test.jsp which will print the timestamp. (<%=new java.util.Date()%> . I still can access the test.jsp with following url without having any WEB-INF directory.

http://localhost:8080/testing/test.jsp


This is unbelievable ! I already tested this myself, at my home and my working place also. Today also I've tested this. But I'm still getting error messages that saying the webapp is not available. I also using both Apache Tomcat, and GlassFish (EJB application server) I don't know how could you run the test.jsp, while the testing folder doesn't contain any WEB-INF directory.

But I'm sure that no one can do this without having a WEB-INF directory inside the testing directory.

Let's see what others saying about this, after testing this themselfs.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Works on Apache Tomcat 5.5.23.
Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 460

Originally posted by Vijitha Kumara:


Yes you can. But that's not a full fledged Web application isn't it.


true, but for just testing jsps like learning we don't need WEB-INF.
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Originally posted by Christophe Verre:
Works on Apache Tomcat 5.5.23.


Hi Christophe,

Are you sure that there are no any WEB-INF directory declared inside the testing directory?

I'm sooooo much confused about how do you do this .

I've tested this with several versions of Apache Tomcat. Today I've tested this using Apache Tomcat 5.5.9. But I didn't use 5.5.23 as you did.

I don't know how this small difference of the above two versions gives a big difference with the output.

Following is the output, I received everyday, when I check this:


Now this is a really confusing problem! Can someone provide an explanation for this? Is it working on only Apache Tomcat 5.5.2 series?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Where did you put the "testing" directory ?
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Originally posted by Christophe Verre:
Where did you put the "testing" directory ?


Inside the webapps directory.
And it works, only if I put a WEB-INF directory inside the "testing" directory.
[ December 11, 2008: Message edited by: Treimin Clark ]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

I think you must put the test.jsp directly inside the webapp directory. Then it will surely work. I think tomcat is not allowing you to use /testing/test.jsp url to access it as it is like using a context root for the jsp. That context root might be occupied by some other web application. I used to test my JSPs by placing then in the webapp directory and they used to run just fine...
[ December 11, 2008: Message edited by: Ankit Garg ]
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Hi Ankit,

I've tested this as you said. But I'm still getting the error message as following:



Ankit, what is your Tomcat version?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Currently I am using Tomcat 6 but previously I used to have Tomcat 5.5 and it used to run fine on it. Did you put the test.jsp file into webapp directory and access it using

http://localhost:8080/test.jsp

Please tell that...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I think you must put the test.jsp directly inside the webapp directory.

That's really something you don't want to do I think Treimin is doing it the right way, but for some reason it doesn't work in his environment.

There should be :
<TOMCAT_DIR>/webapps/testing/test.jsp
And access it with
http://localhost:8080/testing/test.jsp (assuming 8080 is the correct port)

It worked with Tomcat 5.5.23.
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Originally posted by Ankit Garg:
Currently I am using Tomcat 6 but previously I used to have Tomcat 5.5 and it used to run fine on it. Did you put the test.jsp file into webapp directory and access it using

http://localhost:8080/test.jsp

Please tell that...


Yes, I'm doing that way. But it doesn't work.


Originally posted by Christophe Verre :
I think Treimin is doing it the right way, but for some reason it doesn't work in his environment....


What do you mean by my environment? I've tested this not only in my computer. I've already tested this in my class and my working place too. So is this problem only for my country ?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Oops! Sorry. What I used to do is place my JSPs inside the <tomcat-home>\webapp\ROOT directory. Then I used to access it as

http://localhost:8080/<file-name>

This may be the wrong way as ROOT contains the tomcat default application or whatever it may be called but this is what was taught to us ...
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Ankit,

Then you are correct, because the ROOT directory already contained a WEB-INF directory.

Did you try something like Christophe mentioned here.

I really confused about how did he get a successful result on that way.
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
Originally posted by Ankit Garg:
Oops! Sorry. What I used to do is place my JSPs inside the <tomcat-home>\webapp\ROOT directory. Then I used to access it as

http://localhost:8080/<file-name>

This may be the wrong way as ROOT contains the tomcat default application or whatever it may be called but this is what was taught to us ...

That's right. And because it already has WEB-INF directoy, you don't feel that you need to create one. Btw, if you create a folder under ROOT (i.e. test) and put your test.jsp into the folder, then it will work at the address like [http://localhost:8080/test/test.jsp]. It seems that you didn't need to have WEB-INF under the test folder, but in reality you are just running it under sub folder of the ROOT application which already has it's own configuration web.xml in its own WEB-INF folder.


“Everything should be as simple as it is, but not simpler.” Albert Einstein
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

To make it clear, I have an application named "testing" under webapps, with only one JSP file. I can access it. Treimin, are you leaving in an overruled country ? We'll have to dig into Tomcat's documentation.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I don't know if it's relevant (and it's too late now for me to dig further ) but there are some interesting comments in this source.

// Silent catch: it's valid that no /WEB-INF/lib directory exists
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

Yes I can access the file if I put my jsp in a directory <tomcat-home>/webapp/test and use the url

http://localhost:8080/test/test.jsp

Actually first I was not able to access it as the context test was already bound. You might also be facing the same problem. Tell you what, you make the name of the directory a weird one like xxyy and then access your jsp page using the url

http://localhost:8080/xxyy/test.jsp
[ December 11, 2008: Message edited by: Ankit Garg ]
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Ouch! The same problem again Ankit,


I gave a phone call to my friend, and asked him to test this. He said that he got the same result as I got, while he is using Tomcat 5.5.9 version, as I do.

What a confusing problem is this :roll:

Time to believe that this problem is either version-dependent or country-dependent
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9321
    
  17

I am using Tomcat 6 and it is working fine. As far as I remember, in my graduation days I used to use Tomcat 5. Try it on Tomcat 6 or 5...
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
I remember that my class teacher demonstrates to us about the WEB-INF directory is mandatory. He put a typical html file in to a sub-directory of "webapps" directory, without having a WEB-INF directory.

And, it didn't work. So, he told that the WEB-INF is mandatory.

As I remember, he used Tomcat 6 for the demonstration.
cesar valencia
Ranch Hand

Joined: Oct 14, 2008
Posts: 33
i use 5.5.27 and it works. maybe i have hot re/deploy enabled or something? do any of the guys getting error tried to restart their tomcat instance?


scjp5, scwcd5
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

He said that he got the same result as I got, while he is using Tomcat 5.5.9 version, as I do.

Why are you all using 5.5.9 ? I'm going to try with 5.5.9.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I've spent a bit of time playing with several Tomcat version :

<TOMCAT_HOME>/webapps/empty/hello.jsp
http://localhost:8080/empty/hello.jsp

In the order I've tried :

5.5.9 : NG
5.5.20 : OK
5.5.15 : NG
5.5.17 : OK
5.5.16 : OK

In the 5.5.16 change log (which I should have checked in the first place ), there is this entry :
Deploy folders which don't have a WEB-INF, and return an error when a context file does not contain a Context element (remm)

Would it be it ?
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Hi Christophe,

Nice discovery!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

"jufengdhj",
Please check your private messages for an important matter.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Guys,

I know I'm late to the party but my quick two cents are - remember that the SCWCD isn't a Tomcat exam!

hth,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

remember that the SCWCD isn't a Tomcat exam!

That's true. Would you say that WEB-INF is mandatory ?
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
I'll be cagey and say that if I was studying for the exam I'd check the spec and not rely on the behaviors of specific containers
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I'd check the spec and not rely on the behaviors of specific containers

That's my motto I find the spec very blurry concerning WEB-INF though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is WEB-INF Directory mandatory ?