Solved

Understanding Paths while Calling JSP File

Posted on 2004-03-23
23
388 Views
Last Modified: 2010-04-01
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.  
0
Comment
Question by:LarryAndro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 6
  • 3
23 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 10659100
> 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.
0
 
LVL 27

Expert Comment

by:rrz
ID: 10659118
>Question #2:
Yes, you got that right.
0
 
LVL 27

Expert Comment

by:rrz
ID: 10659196
>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)  
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:rrz
ID: 10659266
You might as well add this to your  Environment Variables    
SET CLASSPATH=.;C:\jakarta-tomcat-5.0.19\common\lib\servlet-api.jar
0
 
LVL 1

Author Comment

by:LarryAndro
ID: 10659270
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?
0
 
LVL 1

Author Comment

by:LarryAndro
ID: 10659359
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?
0
 
LVL 27

Expert Comment

by:rrz
ID: 10659527
>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
0
 
LVL 27

Expert Comment

by:rrz
ID: 10659551
SET CLASSPATH=.;C:\Program Files\Apache Group\Tomcat 5.0\common\lib\servlet-api.jar  
0
 
LVL 1

Author Comment

by:LarryAndro
ID: 10659786
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?
0
 
LVL 1

Author Comment

by:LarryAndro
ID: 10659801
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!)
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10659856
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.
0
 
LVL 27

Expert Comment

by:rrz
ID: 10659924
>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  ?
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10660045
You are right!
And the recent version of tomcat actually doesn't even require that var to be set.
0
 
LVL 27

Expert Comment

by:rrz
ID: 10660359
>And the recent version of tomcat actually doesn't even require that var to be set.  
Thanks kenneth, I did not know that.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10660547
no problem. it will determine the path and set it in setup.bat or setup.sh by itself.
0
 
LVL 1

Author Comment

by:LarryAndro
ID: 10661104
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.
0
 
LVL 27

Expert Comment

by:rrz
ID: 10661239
>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.
0
 
LVL 27

Expert Comment

by:rrz
ID: 10661631
You could change the name of  your file to   lja.jsp   and then try your testing.
0
 
LVL 27

Expert Comment

by:rrz
ID: 10661656
Sorry I didn't think that through all the way.
0
 
LVL 27

Expert Comment

by:rrz
ID: 10661841
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.

 
0
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 10661902
I guess you should think about creating your own context soon.  
Then those urls in my last post will become  
http://localhost:8080/yourContext/myServlet   
http://localhost:8080/yourContext/myJSP
0
 
LVL 1

Author Comment

by:LarryAndro
ID: 10662152
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!  
0
 
LVL 27

Expert Comment

by:rrz
ID: 10663761
Larry, thanks for the points. Please feel free to ask any follow ups here.  rrz
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article discusses how to implement server side field validation and display customized error messages to the client.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question