Link to home
Start Free TrialLog in
Avatar of LarryAndro
LarryAndro

asked on

Understanding Paths while Calling JSP File

I'm working thru a JSP book now, and am doing well overall.  But, I don't think I'm understanding "paths" sufficiently.  I would like some general help paths used during compilation of java and jsp files, using my setup.  (After getting better knowledge about paths, I can probably answer my own questions about my compilation problems.)

Following is some info about my directory structure, environment variables, etc.  Specific questions at bottom.

Environment Variables
---------------------
JAVA_HOME = C:\J2ee142\j2eeri1.4-src\publish.windows\WINNT4.0_DBG.OBJ\jdk
TOMCAT_HOME = C:\Program Files\Apache Group\Tomcat 5.0\
Path = %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;C:\Program Files\UltraEdit;C:\J2ee142\j2eeri1.4-src\publish.windows\WINNT4.0_DBG.OBJ\jdk\BIN

Example From Book
-----------------
(Book instructed me to create) One JSP file in the C:\Program Files\Apache Group\Tomcat 5.0\webapps\Book\jsp directory.

(Book instructed me to create) Two JAVA files in the C:\Program Files\Apache Group\Tomcat 5.0\webapps\Book\WEB-INF\Classes\Scripting directory.

I start the Tomcat 5.0 server, then in Internet Explorer enter...  http://localhost:8080/Book/jsp/ExpenseReport.jsp and get some errors I don't understand.  But, for the moment, I don't want to get into my compilation errors.  I would like some information about what is happening as far as search and compilation paths.

Question #1: The JSP file is in an entirely different directory from the two JAVA (compiled to class) files.  How does the JSP file in ...\webapps\Book\jsp find the Class files in the ...\webapps\Book\WEB-INF\Classes\Scripting directory?  

Question #2: When I call the jsp file from my browser it looks like it compiles it into a Java file, that it (I think) tries to convert to a class file.  This activity seems to occur in the C:\Program Files\Apache Group\Tomcat 5.0\work\Catalina\localhost\Book\org\apache\jsp\jsp\ directory.  What is happening here?  is this directory a scratch working directory that is auto-created when a JSP file is called?

More details if needed.  
Avatar of rrz
rrz
Flag of United States of America image

> How does the JSP file in ...\webapps\Book\jsp find the Class files in the ...\webapps\Book\WEB-INF\Classes\Scripting directory?  
Look at
C:\Program Files\Apache Group\Tomcat 5.0\webapps\tomcat-docs\class-loader-howto.html  
Incidently, using spaces in paths sometomes creates problems.
>Question #2:
Yes, you got that right.
>TOMCAT_HOME = C:\Program Files\Apache Group\Tomcat 5.0\
this is wrong for Tomcat 5  
CATALINA_HOME= C:\Program Files\Apache Group\Tomcat 5.0  
or if take my advice   and get rid of spaces
CATALINA_HOME= C:\jakarta-tomcat-5.0.19    ( or whatever number you are working with)  
You might as well add this to your  Environment Variables    
SET CLASSPATH=.;C:\jakarta-tomcat-5.0.19\common\lib\servlet-api.jar
Avatar of LarryAndro
LarryAndro

ASKER

The class-loader-howto.html document looks like what I need.  I'll read it over the next hour and get back.
As for spaces in paths, should I change the long file/directory name to the shortened 8.n form?  For example, should I change

   TOMCAT_HOME=c:\Program Files\Apache Group\Tomcat 5.0    

to

   TOMCAT_HOME=c:\Progra~1\Apache~1\Tomcat~1?
You suggested that I add a CLASSPATH of .;C:\jakarta-tomcat-5.0.19\common\lib\servlet-api.jar.  My directory is slightly different.  So, I found the equivalent location...  C:\Program Files\Apache Group\Tomcat 5.0\common\lib... and entered .;C:\Program Files\Apache Group\Tomcat 5.0\common\lib as an environment variable CLASSPATH.  Did I do this correctly?
>TOMCAT_HOME=c:\Progra~1\Apache~1\Tomcat~1?    
I guess using the DOS names is Ok.  But  
CATALINA_HOME=c:\Progra~1\Apache~1\Tomcat~1
SET CLASSPATH=.;C:\Program Files\Apache Group\Tomcat 5.0\common\lib\servlet-api.jar  
TOMCAT_HOME is set to C:\Program Files\Apache Group\Tomcat 5.0\.  I just created a new environment variable CATALINE_HOME and also set it to C:\Program Files\Apache Group\Tomcat 5.0\.  

I reset my CLASSPATH as you suggested above... SET CLASSPATH=.;C:\Program Files\Apache Group\Tomcat 5.0\common\lib\servlet-api.jar  

I'm not switching to DOS names yet.  But, will keep this in mind as a possible source of problems in the future.  

Does all the above sound OK?
This is my first question ever, rrz@871311.  I assume I ACCEPT when this discussion is over.  And, I sense it is drawing to a close.  (I'm certainly getting what I needed!)
Just my 2 cents info: picking up class files from WEB-INF/classes directory is part of the servlet specification that all server, including tomcat, have to follow.
>TOMCAT_HOME is set to C:\Program Files\Apache Group\Tomcat 5.0\.  I just created a new environment variable CATALINE_HOME and also set it to C:\Program Files\Apache Group\Tomcat 5.0\.  

No, the TOMCAT_HOME  env var  was used in older versions of Tomcat.  I don't know if anything is still looking for it.  

Help kenneth, am I right or wrong  ?
You are right!
And the recent version of tomcat actually doesn't even require that var to be set.
>And the recent version of tomcat actually doesn't even require that var to be set.  
Thanks kenneth, I did not know that.
no problem. it will determine the path and set it in setup.bat or setup.sh by itself.
I'm getting closer to understanding paths.  But, I still have holes when I try to apply my understanding.  Here's my directory structure...

Program Files
---Apache Group
------Tomcat 5.0
---------webapps
------------ROOT  
---------------WEB-INF
------------------classes
---------------------Book
------------------------jsp
------------------------Scripting

After reading, my understanding is that when classes are loaded, it occurs in the following order...

1st = Bootstrap classes of JVM loader
2nd = System class loader
3rd = WEB-INF/classes

So, am I right in thinking that any class file in any subdirectory under the ROOT subdirectory will be found when a JSP page is run (after the 1st and 2nd locations are exhausted)?

I'm also not understanding paths in the context of the browser.

Here are my environment variables...

CATALINA_HOME=C:\Program Files\Apache Group\Tomcat 5.0\
CLASSPATH=.;C:\Program Files\Apache Group\Tomcat 5.0\common\lib\servlet-api.jar

In trying to understand how paths are traversed, I created a small HTML file called lja.html.  I placed a copy of it on all directories starting with ROOT, going all the way down to Scripting.  I then edited each copy so that when invoked it would print out the name of the resident directory.

Then, I started the Tomcat server, and a browser page and entered... http://localhost:8080/lja.html.  A page opened showing that the lja.html file resident on

------------ROOT

was invoked.  Then, I entered http://localhost:8080/WEB-INF/lja.html and I got a 404 not found error.  I tried all of the following, (for there was a copy of lja.html in all these locations)...

http://localhost:8080/WEB-INF/lja.html
http://localhost:8080/WEB-INF/classes/lja.html
http://localhost:8080/WEB-INF/classes/Book/lja.html
http://localhost:8080/WEB-INF/classes/Book//jsp/lja.html

What am I missing?  I think of http://localhost:8080 as equaling...

------------ROOT  

and so thought I could append additional path subdirectories.
>Then, I entered http://localhost:8080/WEB-INF/lja.html and I got a 404 not found  
Yes, because WEB-INF is for Tomcat use only and not available to browser.
You could change the name of  your file to   lja.jsp   and then try your testing.
Sorry I didn't think that through all the way.
The WEB-INF directory is just  where put your classes (in classes) and jars (in lib).
Also it contains web.xml  where you can  name and map your  servlets and if you want your JSP files as well.   Once you name name and map your servlets and JSPs, you can use  
http://localhost:8080/myServlet 
http://localhost:8080/myJSP     

If you want examples of naming and mapping, then ask here. Or just look at the web.xml in the pre-installed contexts in Tomcat's webapps directory.

 
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is making sense!  These questions and answers could go on forever.  But, my basic "need to understand paths" question is by and large answered.  I'm going to take a day and read and practice.  But, I'm very satisfied to draw this question to a close.  Thanks, rrz!  
Larry, thanks for the points. Please feel free to ask any follow ups here.  rrz