• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Chris Staten
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,

How about you try this?


http://localhost:8080/tutorial/errhandler.jsp



Joyce
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic