wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Can I view my .jsp files from outside of my Tomcat directory? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Can I view my .jsp files from outside of my Tomcat directory?" Watch "Can I view my .jsp files from outside of my Tomcat directory?" New topic
Author

Can I view my .jsp files from outside of my Tomcat directory?

Chris Staten
Ranch Hand

Joined: Sep 24, 2004
Posts: 101
I was having a problem with trying to run my .jsp pages locally where I kept getting a �The requested resource (�) is not available� error. I fixed this by moving my .jsp pages into my Tomcat directory (C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\�) and redirecting my localhost virtual directory to the Tomcat 5.0 folder.

My question is if I can save my .jsp files outside of the Tomcat 5.0 folder and still view the pages using Tomcat? I was thinking that there may be a way to use an environment variable to do this, but I�m not sure.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

You need to set up the appropriate docbase for the context in the server.xml file.

All my applications exist outside the Tomvcat folder hierarchy.

Here's an actual example from my server.xml:


[ October 15, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Chris Staten
Ranch Hand

Joined: Sep 24, 2004
Posts: 101
Hey Bear, thanks for the reply. I tried to place a context element in my server.xml file, but I still can�t get it to work. I�ve been reading about the Context container on the apache web site (http://jakarta.apache.org/tomcat/tomcat-4.0-doc/config/context.html), but I�m still a little lost on how to make this work.

Here�s what I�ve done:
I nested a context element inside the host element of my server.xml file. Here is a cut and paste version of it
<Context path="/tutorial" docBase="C:/Documents and Settings/CSTATEN/My Documents/programming/code/jsp/tutorials/jsp_fundamentals/exception_handling" debug="0" reloadable="true" crossContext="false"/>

I changed the name associated with the path attribute and changed the docBase attribute to point to the folder that my .jsp files are in. I�ve changed localhost to point at C:/Documents and Settings/CSTATEN/My Documents/programming/code/jsp

When I want to view my .jsp file I go to http://localhost/tutorials/jsp_fundamentals/exception_handling/errhandler.jsp, but I keep getting a 404 - file not found error

Not sure if I�ve put the context element in the wrong place, or just hosed up its attributes.
Chris Staten
Ranch Hand

Joined: Sep 24, 2004
Posts: 101
My post above does not include the port specification in the URI for trying to call my jsp files, sorry. With it in there I still get a 404 error.

Should have been:
http://localhost:8080/tutorial/tutorials/jsp_fundamentals/exception_handling/errhandler.js
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

The folder pointed to by the docbase must be a fully compliant web application. That means at minimum it needs a WEB-INF folder and a minimal web.xml file. You do that?

Also, what do you mean by "I set localhost"? localhost? What are you messing with that for?
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Chris,

How about you try this?



Joyce
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Steps
-----
1. Assume you have a Hello.jsp under c:\chris\web directory.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>JSP Test</TITLE></HEAD>
<BODY BGCOLOR="#FDF5E6">
<H1>JSP Test</H1>
Time: <%= new java.util.Date() %>
</BODY>
</HTML>


2. Modify the server.xml file

<Host...>
<Context docBase="c:\chris\web" path="/jsp-testing">
</Context>
:
</Host>


3. startup the tomcat server.

4. http://localhost:8080/jsp-testing/Hello.jsp

It worked on my system.

Joyce
[ October 18, 2004: Message edited by: Joyce Lee ]
Chris Staten
Ranch Hand

Joined: Sep 24, 2004
Posts: 101
OK, now I�m really confused because Joyce�s link worked like a charm. There are a few reasons that I�m confused, but the main one is that I commented the context element out of my server.xml file and it still worked. I even rebooted the whole system (not just shutdown and startup Tomcat).

Bear, I changed the localhost variable thinking that if I pointed it at the root of my code directory then IIS would look in that directory for my .jsp files. I guess that I�m thinking too much about dealing with .aspx files. Heck, I don�t even know what I�m thinking about now.

The good thing is that my O�REILLY Head First Servlets & JSP book just showed up about 15 minutes ago, Kathy, Bert, and Bryan I love you guys!!



EDIT:
For clarification, Joyce�s link that I refer to in this post is the http://localhost:8080/tutorial/errhandler.jsp link.
[ October 18, 2004: Message edited by: Chris Staten ]
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Originally posted by Chris Staten:

The good thing is that my O�REILLY Head First Servlets & JSP book just showed up about 15 minutes ago, Kathy, Bert, and Bryan I love you guys!!



So you're one of the O'reilly Head First series fans, just like me. Now I'm waiting for the Head First Design Patterns to be released.
Chris Staten
Ranch Hand

Joined: Sep 24, 2004
Posts: 101
Bear, it�s working by aiming my browser to http://<path name>/<pagename>.jsp, where the context element looks like:

<Context path="/tutorial" docBase="C:/Documents and Settings/CSTATEN/My Documents/programming/code/jsp/tutorials/jsp_fundamentals/exception_handling" debug="0" reloadable="true" crossContext="false"/>

and my <pagename>.jsp file (errhandler.jsp) is in the following directory:

C:/Documents and Settings/CSTATEN/My Documents/programming/code/jsp/tutorials/jsp_fundamentals/exception_handling

The only files in this directory are two .jsp files, no WEB-INF folder or web.xml file. Could it be that Tomcat is getting that information from the �ROOT� directory in the Tomcat application directory (C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT)?


Also, I�ve been talking to myself (very troubling I know ) and I�m thinking that the reason that the http://tutorial/errhandler.jsp link works even though I�ve commented it out of my server.xml file is because the server.xml file writes this information to some .ini file. Therefore, even though the context element is commented out of the server.xml file, it (or whatever result it causes to happen) is still in the .ini file. How close is this to the truth?

Joyce, yes I am a fan of the O'REILLY Head First series. They keep me awake while I read
[ October 18, 2004: Message edited by: Chris Staten ]
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Originally posted by Chris Staten:
Also, I�ve been talking to myself (very troubling I know ) and I�m thinking that the reason that the http://tutorial/errhandler.jsp link works even though I�ve commented it out of my server.xml file is because the server.xml file writes this information to some .ini file. Therefore, even though the context element is commented out of the server.xml file, it (or whatever result it causes to happen) is still in the .ini file. How close is this to the truth?


Try "Refresh" the browser or clear the temporary internet files: Tools->Internet Options.

Joyce
[ October 18, 2004: Message edited by: Joyce Lee ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I view my .jsp files from outside of my Tomcat directory?
 
Similar Threads
set up context path
simple JSP and JavaBean, error 500
Can we saperate Jsp files folder from Tomcat?
Tomcat webapp
Eclipse Source Folder Management