2

I've got Apache running on my server, and some VHosts set up for myself through this; however, the apache documentRoot, nor any VHost's documentRoot appear to be calling tomcat to process any JSP files - in order to run a JSP, I need to upload it as a war archive, and access it via domain:8080.

Would anyone be able to point me in the right direction on getting tomcat set up so that it can process JSP files as normal?

emecas
  • 1,586
  • 3
  • 27
  • 43
Eoghan
  • 1,720
  • 2
  • 17
  • 35
  • are you asking how to install tomcat? By the way, what is your environment? – emecas Feb 16 '14 at 13:43
  • Tomcat is installed, and accessible via the :8080 port - any .war files uploaded to here run fine. Standalone JSP's under documentRoot aren't processed at all. Running on CentOS6.4 x64 – Eoghan Feb 16 '14 at 14:20
  • Please reformat your question so it matches your own answer. – Cedric Simon Feb 26 '14 at 17:06

3 Answers3

-1

If I understand you correctly, you want to have JSP deployed outside of a war/webapps. Unfortunately, Tomcat does not work that way. You have to deploy your JSP as a WAR/folder-in-webapps. Unlike PHP or some such language plugin, Tomcat hosts Java apps. It does not process JSP files.

To get pass through, have you tried the mod_jk or as it is known now, the connector? http://tomcat.apache.org/connectors-doc/miscellaneous/faq.html

Virmundi
  • 2,497
  • 3
  • 25
  • 34
  • Please check my below answer; I found that it is possible to do this with mod jk_serv, and setting up workers appropriately. – Eoghan Feb 25 '14 at 18:20
  • mod_jk is only to serve non java files outside the WAR, not for JSP. mod_jk allow you to have some pages managed by apache httpd, and some others taken from Tomcat, but does not modify Tomcat configuration or behaviour. mod_jk is very usefull to server images, js files, etc... from apache httpd, and so not require Tomcat to serve them. – Cedric Simon Feb 26 '14 at 17:05
-1

Answering my own question on this, as neither solution offered what I was looking for.

Firstly, I downloaded and compiled the apache mod jk_serv; following this, I configured a worker, under workers.properties with the following;

workers.tomcat_home=/opt/apache-tomcat-7.0.50

workers.java_home=/opt/jdk1.7.0_51/

ps=/

worker.list=ajp13_worker
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
worker.ajp13_worker.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13_worker

Following this, under apache's conf.d, I set up a worker config to be loaded by apache, as follows;

LoadModule jk_module modules/mod_jk.so

JkWorkersFile /etc/httpd/conf/workers.properties
JkLogFile     /var/log/httpd/mod_jk_log
JkShmFile     /var/log/httpd/jk-runtime-status
JkWatchdogInterval 60
JkLogLevel    info

JkMountCopy   All

# all the contexts:
JkMount        / worker1
JkMount        /*.jsp worker1

Finally, I set up a script that would update tomcat's server.xml, to add any relevant vHosts that were added to httpd.conf.

With this, jsp files are now processed on-the-fly; without the need for uploading seperate WAR's.

Eoghan
  • 1,720
  • 2
  • 17
  • 35
  • You are not setting up your Tomcat to access it via localhost:8080 but you are setting up Apache to connect to port 80. Also I don't think above config will deploy your war under localhost but under localhost/warFileName, so it does not solve the question at all. – Cedric Simon Feb 25 '14 at 18:59
  • Note: even if you did deploy using a WAR file, you can ALWAYS modify or replace/add JSP in the subfolder, and they will be effective directly (but the site content sill not march the WAR file anymore). – Cedric Simon Feb 25 '14 at 19:02
-2

You simply need to copy your WAR file into the $TOMCAT/webapps/ folder and define a context in server.xml (or context.xml) for it, so it points to the root. in server.xml, contexts are defined inside a <Host>.

I would also advise you to remove the ROOT folder under $TOMCAT/webapps/ if any has been created.

Below an example of context definition:

<Host name="192.168.0.251"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
<Alias>myhost.mydomain.com</Alias>
<Context docBase="myWarFileName" path="" reloadable="true" source="myWarFileName">

... Add any resource, etc.. for this context here, if any ...

</Context>
</Host>

Note the empty path value, pointing then to the root directory. In some cases I have had to use "/" instead of an empty string.

Cedric Simon
  • 4,571
  • 4
  • 40
  • 52