Archive for the ‘Tomcat’ Category

Tomcat: Installing mod_jk with Apache on Linux

Friday, August 27th, 2010

1) Download Mod_JK

2) Copy it in the /etc/httpd/module as jk_module.so

3) Add the following in the /etc/httpd/httpd.conf

LoadModule jk_module modules/mod_jk.so

JkWorkersFile /etc/httpd/conf/workers.properties
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info

4) Have the following in workers.properties

worker.list=workerD,worker81

#workerD (default) 8080
worker.workerD.type=ajp13
worker.workerD.host=localhost
worker.workerD.port=8009

worker.worker81.type=ajp13
worker.worker81.host=localhost
worker.worker81.port=8109

Tomcat: Session Timeout

Thursday, August 5th, 2010

In the Web.xml

 <web-app>
  <session-config>
    <session-timeout>60</session-timeout>
  </session-config>
...
 </web-app>

Tomcat: remote debugging setup

Friday, November 20th, 2009
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
bin/catalina.bat jpda start

Source

Java: Servlet Set Expires Header with Cache Control

Saturday, March 28th, 2009

When setting the expires date in Servlet, better to set the cache-control as well.

final int CACHE_DURATION_IN_SECOND = 60 * 60 * 24 * 2; // 2 days
final long   CACHE_DURATION_IN_MS = CACHE_DURATION_IN_SECOND  * 1000;
long now = System.currentTimeMillis();
//res being the HttpServletResponse of the request
res.addHeader("Cache-Control", "max-age=" + CACHE_DURATION_IN_SECOND);
res.addHeader("Cache-Control", "must-revalidate");//optional
res.setDateHeader("Last-Modified", now);
res.setDateHeader("Expires", now + CACHE_DURATION_IN_MS);

For no cache

res.setHeader("Pragma", "No-cache");
res.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
res.setDateHeader("Expires", 1);

Tomcat: Virtual Hosting and Web App

Sunday, November 2nd, 2008

To map a domain name to a “war” web application.

File: [tomcat-path]/conf/server.xml

<Service>….
<Service>….
<Engine>…

<Host name="www.yourdomain.com" appBase="webapps/webappname" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="."/>
<Alias>yourdomain.com</Alias>
</Host>


</Engine>
</Service>
</Server>

Note: This obviously assumes that this domain name is mapped to the specific tomcat instance.