• 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

Running JSP from outside tomcat\webapps\ROOT

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

To run jsp applications, we save jsp files in tomcat\webapps\ROOT folder.
But if I want to execute jsp files from anywhere but not in ROOT folder, let in c:\Test folder then what should I do? what would be changes in configuration? and which file configuration should be changed?

Bye....
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

To run jsp applications, we save jsp files in tomcat\webapps\ROOT folder.


No, you usually make a new folder in webapps. For example :
webapps/myapp/hello.jsp

And access it (after rebooting Tomcat) via localhost:8080/myapp/hello.jsp
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by abhijeet srivastava:

But if I want to execute jsp files from anywhere but not in ROOT folder



Please Check this Link to Set Up Your Development Environment
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several ways you can do this and they are container specific.
Moving to the Apache Tomcat forum.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat doesn't run "JSPs".
It runs web applications (which can contain JSPs).

So, the first thing you need to do is create a proper web application directory structure.
Suppose your app is to be named "myApp".
Create a directory named "myApp" and put it wherever you like.
Then, inside the myApp directory create another directory named "WEB-INF" (case sensitive).
OK, now you have a proper web application directory structure.
Put your JSPs in the myApp directory.

Now there are several ways you could deploy your web app.
1.) Drop the myApp directory (and all of its contents) in the {Tomcat install}/webapps directory.
Tomcat will automatically deploy the application for you .
You can then access your app with the following URL:
http://localhost:8080/myApp

2.) (this is probably what you're looking for)
Leave the myApp directory where is is and create a context fragment file
that lets Tomcat know where your app is.
Context fragment files go under:
{tomcat install}/conf/Catalina/localhost
The name of the file should match your contextPath ("myApp") with
a ".xml" extension.

Assuming you've created the myApp directory under "C:\Test", here
is an example context fragment file (named myApp.xml).


Once you've created this file and placed it in the tomcat/conf/Catalina/localhost directory, Tomcat will deploy your app.
You will be able to access it with:
http://localhost:8080/myApp


Hope this helps.
[ September 27, 2006: Message edited by: Ben Souther ]
 
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry for excavation of 9 year old thread, but I just found it in Google and I have a useful comment for future fellow Googlers.

The Context can be also added directly in server.xml inside <Host> element, like this:



In this example, the folder C:\Test\images will be accessible under example.com/images/.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Scheller wrote:
The Context can be also added directly in server.xml inside <Host> element, like this:





Nonononono!

Do not put Context elements in server.xml.

That practice has been discouraged for many, many years. In fact, I think it was deprecated even at the time this thread was originally started.

If you place a Context element in server.xml, it requires a Tomcat restart to update the context. Plus you're at risk for corrupting the server.xml file and thereby making Tomcat completely unable to start.

You can place a Context in the webapp's META-INF/context.xml file, or as a file (with the same name as the context) under TOMCAT_HOME/conf/Catalina/localhost (assuming you're not using a custom Host configuration).

But don't put it in server.xml!
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Tim for informing me about that.

The information about the possibility of placing a Context in META-INF is wonderful. Now I have to remove all the instructions about additional configuration of Host from readme file, because I can easily "embed" the Context in my webapp!

Your arguments certainly show it is not the best practice to nest Context in Host, but I am not sure if it is deprecated at all. Neither Tomcat 7 nor 8 show any deprecation messages. The docs don't say anything about deprecation as well. Docs for Tomcat 8 say that I can nest Context in Host, and there is nothing about deprecation:

Inside the Host element, you can nest Context elements for the web applications associated with this virtual host.

 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The docs probably don't say "deprecated". But if you read them in detail, you will see that they do say NOT to do it. The reason being - like I said (and so should the Tomcat docs) - that placing a Context in server.xml means that you cannot dynamically update the webapp.

The server.xml file only gets digested when Tomcat starts up. so any changes to it will not be detected until the next Tomcat startup.

Context.xml files in conf/Catalina/localhost are normally scanned every few seconds, so changes to those Context definitions get applied fairly rapidly. Without the need to restart Tomcat.
 
Andrew Polansky
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And due to this argument I got my Context moved away from server.xml. Thank you again for the tip.
 
reply
    Bookmark Topic Watch Topic
  • New Topic