File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running JSP from outside tomcat\webapps\ROOT

 
abhijeet srivastava
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • 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....
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Adam Scheller
Ranch Hand
Pie
Posts: 238
15
Linux MS IE
  • 0
  • Mark post as helpful
  • send pies
  • 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/.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 1
  • Mark post as helpful
  • send pies
  • 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!
 
Adam Scheller
Ranch Hand
Pie
Posts: 238
15
Linux MS IE
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Adam Scheller
Ranch Hand
Pie
Posts: 238
15
Linux MS IE
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic