martedì, aprile 24, 2007

errorPage in jsp vs error-page in web.xml

I had an argument with my colleague (and friend) Armand about how to manage exception in web application. Basically there are two ways to manage exception in web application:
- using error-page in the deployment descriptor;
- using the directive "errorPage" in the jsp.
Armand said that using the declaration in the web.xml is enough to manage all the possible error conditions. I agreed with him but I wanted to find a reason to make allowance for errorPage directive in the jsp.
I asked to Lucio the question and he said that using errorPage allow having different jsp pages, managing the error conditions, for different jsp, and you can't have the same behavior using error-page tag in web.xml because, in a such case, you can only specify the type of Exception.

venerdì, aprile 20, 2007

singleton for tomcat

If you want having just one singleton class shared by all the web applications of your tomcat instance, you have to put the jar containing your singleton class in the folder tomcat/shared and don't put it in the WEB-INF/lib folder of your webapp. In this way the instance will be created just once,after the first call to the method MySingleton.getInstance() and it will be a real singleton object shared between all the webapps.
I needed a such behavior because I want to implement a centralized management of rules, using acegi framework in my project.

mercoledì, aprile 18, 2007

switching off apache web server and using tomcat

Here my notes about how switching off apache httpd web server of my virtual server on
I don't know if this solution could be applied for different domain providers.

1) vi /etc/rc.conf
2) change the entry httpd_enable="YES" to httpd_enable="NO"
3) run command rebootvs

At this point you have disabled your apache web server httpd. Now you have to change the listening port of your tomcat.

1) cd /usr/local/jakarta-tomcat/conf
2) chmod 777 server.xml
3) vi server.xml
4) search for listening port (usually is configured as 8180) and change the value to 8080.
5) save the changes and run command rebootvs.

At this point your apache tomcat is listening on port 8080 (and port 80...why?) on your virtual server.
Try to connect using http://mydomain/mywebapp.

I have applied this solution to my website, and now it works.
Many thanks to Giovanni Remigi (Ireland) for his tips.