Saturday, October 30, 2010

Tomcat Custom 404 Page

This post will cover creating a custom 404 Error page for Tomcat.

By default, if a requested page does not exist, a 404 Error is raised and the user is served Tomcat's default 404 error page as below:

Above, I requested a page called 'david' which does not exist.

To make your 404 page a bit more presentable, provide the user with a link back into your site, as well as hide the Tomcat version in use, you can easily add a custom 404 error page.

Start by creating the page you wish to use. In my case, I am creating a page called 'NotFound.jsp'

Add the 404 page you crated to your site directory.

Now, in your $CATALINA_HOME/conf directory, edit your web.xml file.

Add the following entry just beneath the welcome-file-list entry as shown below:



Now, when someone goes to a page that does not exist, they get the custom 404 page we created.

for example:

SEO Disclaimer: I've called my page NotFound.jsp page and have added a meta-tag:

meta content="noindex" name="robots">

I did this as it (supposedly), the tag will stop search engined from indexing my 404 page.  I'm not an SEO guy so whether this is necessary  (or even a good idea), I don't know.  You could, of course, place your 404 page within a sub directory (e.g. '404') and adjust the location in your web.xml from /404/NotFound.jsp to /NotFound.jsp. You could then add a robots.txt file to prevent crawling of the directory.

Related Posts:
Install Tomcat 6 on CentOS
Tomcat Oracle JDBC Connection
Tomcat Manager Password

Install PostgreSQL 9 on CentOS

PLEASE NOTE: I have created an updated and much expanded installation guide for PostgreSQL 9.1 here:


This post will cover installing PostgreSQL 9 on CentOS.
PostgreSQL 9 is the first major release from PostgreSQL in some time and the directory structure has changed. If you are using Webmin, we will also show how to configure Webmin to manage PostgreSQL 9. PLEASE NOTE: If you are looking to install PostgreSQL 9 on cPanel, please see my step-by-step guide here: We'll use the simplest method to install, which is the postrgres repo rpms.
Begin by locating the appropriate one here: 
There is a 9.1.1 Alpha version available, but I am going to install 9.0.2

For CentOS I will need:

So, using wget: 

[root@server1 ~]# wget
--2010-10-29 15:38:15--
Connecting to||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4623 (4.5K) [application/x-rpm]
Saving to: `pgdg-centos-9.0-2.noarch.rpm'

100%[======================================>] 4,623       --.-K/s   in 0s

2010-10-29 15:38:15 (259 MB/s) - `pgdg-centos-9.0-2.noarch.rpm' saved [4623/4623]
Now install the repo....
[root@server1 ~]# rpm -i pgdg-centos-9.0-2.noarch.rpm
We now need to edit the CentOS-Base.repo to exclude postgre. To do, so we simply edit CentOS-Base.repo and add 'exclude=postgresql*' to the [base] and [updates] sections:
[root@server1 ~]# cd /etc/yum.repos.d
[root@server1 yum.repos.d]# vi CentOS-Base.repo
name=CentOS-$releasever - Base

#released updates
name=CentOS-$releasever - Updates
Now, let's use 'yum list' to check the packages that are now available.
[root@server1 yum.repos.d]# yum list postgres*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons:
 * base:
 * extras:
 * updates:
pgdg90                                                   | 2.8 kB     00:00
pgdg90/primary_db                                        |  57 kB     00:00
Excluding Packages from CentOS-5 - Base
Excluding Packages from CentOS-5 - Updates
Installed Packages
postgresql-libs.x86_64                    8.1.18-2.el5_4.1             installed
Available Packages
postgresql-jdbc90.x86_64                  9.0.801-1PGDG.rhel5          pgdg90
postgresql-jdbc90-debuginfo.x86_64        9.0.801-1PGDG.rhel5          pgdg90
postgresql90.x86_64                       9.0.4-1PGDG.rhel5            pgdg90
postgresql90-contrib.x86_64               9.0.4-1PGDG.rhel5            pgdg90
postgresql90-debuginfo.x86_64             9.0.4-1PGDG.rhel5            pgdg90
postgresql90-devel.x86_64                 9.0.4-1PGDG.rhel5            pgdg90
postgresql90-docs.x86_64                  9.0.4-1PGDG.rhel5            pgdg90
postgresql90-jdbc.x86_64                  9.0.801-1PGDG.rhel5          pgdg90
postgresql90-jdbc-debuginfo.x86_64        9.0.801-1PGDG.rhel5          pgdg90
postgresql90-libs.i386                    9.0.4-1PGDG.rhel5            pgdg90
postgresql90-libs.x86_64                  9.0.4-1PGDG.rhel5            pgdg90
postgresql90-odbc.x86_64                  09.00.0200-1PGDG.rhel5       pgdg90
postgresql90-odbc-debuginfo.x86_64        09.00.0200-1PGDG.rhel5       pgdg90
postgresql90-plperl.x86_64                9.0.4-1PGDG.rhel5            pgdg90
postgresql90-plpython.x86_64              9.0.4-1PGDG.rhel5            pgdg90
postgresql90-pltcl.x86_64                 9.0.4-1PGDG.rhel5            pgdg90
postgresql90-python.x86_64                4.0-2PGDG.rhel5              pgdg90
postgresql90-python-debuginfo.x86_64      4.0-2PGDG.rhel5              pgdg90
postgresql90-server.x86_64                9.0.4-1PGDG.rhel5            pgdg90
postgresql90-test.x86_64                  9.0.4-1PGDG.rhel5            pgdg90
postgresql_autodoc.noarch                 1.40-1.rhel5                 pgdg90
[root@server1 yum.repos.d]#
We can now install PostgreSQL 9 using yum: yum install postgresql90 postgresql90-devel postgresql90-server postgresql90-libs
[root@server1 ~]# yum install postgresql90 postgresql90-devel postgresql90-server postgresql90-libs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons:
 * base:
 * extras:
 * updates:
Excluding Packages from CentOS-5 - Base
Excluding Packages from CentOS-5 - Updates
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postgresql90.x86_64 0:9.0.4-1PGDG.rhel5 set to be updated
--> Processing Dependency: for package: postgresql90
---> Package postgresql90-devel.x86_64 0:9.0.4-1PGDG.rhel5 set to be updated
---> Package postgresql90-libs.i386 0:9.0.4-1PGDG.rhel5 set to be updated
--> Processing Dependency: for package: postgresql90-libs
---> Package postgresql90-libs.x86_64 0:9.0.4-1PGDG.rhel5 set to be updated
---> Package postgresql90-server.x86_64 0:9.0.4-1PGDG.rhel5 set to be updated
--> Running transaction check
---> Package libxslt.x86_64 0:1.1.17-2.el5_2.2 set to be updated
---> Package openldap.i386 0:2.3.43-12.el5_6.7 set to be updated
--> Processing Dependency: for package: openldap
---> Package openldap.x86_64 0:2.3.43-12.el5_6.7 set to be updated
--> Running transaction check
---> Package cyrus-sasl-lib.i386 0:2.1.22-5.el5_4.3 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

 Package                  Arch        Version                Repository    Size
 postgresql90             x86_64      9.0.4-1PGDG.rhel5      pgdg90       1.4 M
 postgresql90-devel       x86_64      9.0.4-1PGDG.rhel5      pgdg90       1.6 M
 postgresql90-libs        i386        9.0.4-1PGDG.rhel5      pgdg90       220 k
 postgresql90-libs        x86_64      9.0.4-1PGDG.rhel5      pgdg90       218 k
 postgresql90-server      x86_64      9.0.4-1PGDG.rhel5      pgdg90       4.8 M
Installing for dependencies:
 cyrus-sasl-lib           i386        2.1.22-5.el5_4.3       base         127 k
 libxslt                  x86_64      1.1.17-2.el5_2.2       base         488 k
 openldap                 i386        2.3.43-12.el5_6.7      updates      296 k
Updating for dependencies:
 openldap                 x86_64      2.3.43-12.el5_6.7      updates      304 k

Transaction Summary
Install      8 Package(s)
Update       1 Package(s)
Remove       0 Package(s)

Total download size: 9.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/9): cyrus-sasl-lib-2.1.22-5.el5_4.3.i386.rpm          | 127 kB     00:00
(2/9): postgresql90-libs-9.0.4-1PGDG.rhel5.x86_64.rpm    | 218 kB     00:00
(3/9): postgresql90-libs-9.0.4-1PGDG.rhel5.i386.rpm      | 220 kB     00:00
(4/9): openldap-2.3.43-12.el5_6.7.i386.rpm               | 296 kB     00:00
(5/9): openldap-2.3.43-12.el5_6.7.x86_64.rpm             | 304 kB     00:00
(6/9): libxslt-1.1.17-2.el5_2.2.x86_64.rpm               | 488 kB     00:00
(7/9): postgresql90-9.0.4-1PGDG.rhel5.x86_64.rpm         | 1.4 MB     00:01
(8/9): postgresql90-devel-9.0.4-1PGDG.rhel5.x86_64.rpm   | 1.6 MB     00:01
(9/9): postgresql90-server-9.0.4-1PGDG.rhel5.x86_64.rpm  | 4.8 MB     00:03
Total                                           978 kB/s | 9.4 MB     00:09
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : openldap                                                1/10
  Installing     : postgresql90-libs                                       2/10
  Installing     : libxslt                                                 3/10
  Installing     : postgresql90                                            4/10
  Installing     : cyrus-sasl-lib                                          5/10
  Installing     : postgresql90-server                                     6/10
  Installing     : postgresql90-devel                                      7/10
  Installing     : openldap                                                8/10
  Installing     : postgresql90-libs                                       9/10
  Cleanup        : openldap                                               10/10

  postgresql90.x86_64 0:9.0.4-1PGDG.rhel5
  postgresql90-devel.x86_64 0:9.0.4-1PGDG.rhel5
  postgresql90-libs.i386 0:9.0.4-1PGDG.rhel5
  postgresql90-libs.x86_64 0:9.0.4-1PGDG.rhel5
  postgresql90-server.x86_64 0:9.0.4-1PGDG.rhel5

Dependency Installed:
  cyrus-sasl-lib.i386 0:2.1.22-5.el5_4.3    libxslt.x86_64 0:1.1.17-2.el5_2.2
  openldap.i386 0:2.3.43-12.el5_6.7

Dependency Updated:
  openldap.x86_64 0:2.3.43-12.el5_6.7

[root@server1 ~]#
We can now initialize Postgre 
*note: when using Webmin, please see 'Configuring Webmin to Manage PostgreSQL9 below):
[root@server1 ~]# service postgresql-9.0 initdb
Start the Postgre server:
[root@server1 ~]# service postgresql-9.0 start
Configuring Webmin to Manage PostegreSQL 9

Due to the directory structure of PostgreSQL 9, you will need to make a few changes to the Webmin management interface it let Webmin know where the Postgre files are located.

Under Servers>PostgreSQL Database Server

Click on Module Configuration.

Make the following substitutions in the System Configuration Section:

1. Path to psql command: 
Original:  /usr/bin/psql
Change to: /usr/pgsql-9.0/bin/psql

2. Command to start PostgreSQL
if [ -r /etc/rc.d/init.d/rhdb ]; then /etc/rc.d/init.d/rhdb start; else /etc/rc.d/init.d/postgresql start; fi
Change to:
if [ -r /etc/rc.d/init.d/rhdb ]; then /etc/rc.d/init.d/rhdb start; else /etc/rc.d/init.d/postgresql-9.0 start; fi
3. Command to stop PostgreSQL 
if [ -r /etc/rc.d/init.d/rhdb ]; then /etc/rc.d/init.d/rhdb stop; else /etc/rc.d/init.d/postgresql stop; fi
Change to:
if [ -r /etc/rc.d/init.d/rhdb ]; then /etc/rc.d/init.d/rhdb stop; else /etc/rc.d/init.d/postgresql-9.0 stop; fi
4. Command to initialize PostgreSQL Original:
if [ -r /etc/rc.d/init.d/rhdb ]; then /etc/rc.d/init.d/rhdb start; else /etc/rc.d/init.d/postgresql initdb ; /etc/rc.d/init.d/postgresql start; fi
Change to:
if [ -r /etc/rc.d/init.d/rhdb ]; then /etc/rc.d/init.d/rhdb start; else /etc/rc.d/init.d/postgresql-9.0 initdb ; /etc/rc.d/init.d/postgresql-9.0 start; fi
5. Path to postmaster PID file Original: /var/run/ Change to: /var/run/ 6. Paths to host access config file Original: /var/lib/pgsql/data/pg_hba.conf Change to: /var/lib/pgsql/9.0/data/pg_hba.conf 7. Default backup repository directory Original: /home/db_repository Change to: /var/lib/pgsql/9.0/backups Save the configuration. If you have not alreay initialized the database, do so now by clicking the initialize database button.
PostgreSQL 9 Hosting PostGIS Hosting Additional information and references: