• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is WEB-INF Directory mandatory ?

 
Somesh Rathi
Ranch Hand
Posts: 31
Eclipse IDE Hibernate Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)...
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 463
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The specification doesn't say that it is mandatory, but a web application without one looks like an apple pie without apples
 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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

Thanks
Kathir
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kathir C:
Hi All,

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


Take a look at the ScwcdLinks .
 
Sai Surya
Ranch Hand
Posts: 463
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works on Apache Tomcat 5.5.23.
 
Sai Surya
Ranch Hand
Posts: 463
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you put the "testing" directory ?
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe,

Nice discovery!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"jufengdhj",
Please check your private messages for an important matter.
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remember that the SCWCD isn't a Tomcat exam!

That's true. Would you say that WEB-INF is mandatory ?
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic