-   Linux - Server (
-   -   Trying to get started with JSP on Debian 5.0 (Lenny) (

MHJCuijpers 09-17-2010 07:52 AM

Trying to get started with JSP on Debian 5.0 (Lenny)
I am trying to get started with JSP on my Debian server. So far, I have installed the following packages:


As far as I can tell, that should be (more than) enough to get started, but I'm at a complete loss how I should configure this. There is a lot of information out there, but I haven't found anything that clearly explains how to configure apache and tomcat to get this to work.

I've added a sample file (index2.jsp) to the default /var/www directory; instead of interpreting the code, it just displays it though.

For now, it's enough to get everything working on the default site - I'm not too worried about security or running multiple sites (yet) as I'm just trying stuff out on a virtual machine.

As an additional note, I'm planning to use the jsp pages together with postgresql - are there any additional packages I should install for that (besides the obvious postgresql?)

bathory 09-17-2010 02:22 PM


I hope this howto, written for Debian, should help you go.


MHJCuijpers 09-20-2010 03:46 AM

Thanks, that article's a great help - the link for tomcat seems broken, though ( - any alternatives to download it? (it might be a temporary problem, I'll try again later)

bathory 09-20-2010 04:10 AM


If you still have problems, you can download it directly from here


MHJCuijpers 09-20-2010 04:38 AM

Thanks, I was able to download it now - I'm afraid I've done something wrong, though - still isn't working (http://localhost by default opens index.html instead of index2.jsp, and when I open http://localhost/index2.jsp, I get the exact contents of the file (including the html tags) displayed in my browser.

Apache and tomcat both start without warnings or error messages, and i can't see anything out of the ordinary in the logfiles.

(I'll probably be trying again tonight, have some other stuff to do now)

bathory 09-20-2010 04:58 AM

Looks like apache does not know how to handle jsp pages.
Make sure you've enabled mod_jk, i.e you ran:

a2enmod jk
and you have the following in apache's configuration

JkMount /* default
JkMount /*.jsp default

Without those, apache cannot pass .jsp pages to tomcat

Regarding index2.jsp, if you want apache to use it an an index page, you should add it in the DirectoryIndex directive.

MHJCuijpers 09-20-2010 05:58 AM

If I run a2enmod jk, I get the message 'Module jk already enabled'. So that was on.

I had already added the following to /etc/apache2/apache2.conf:


# Enable Jk for all sites
JkMount /* default
JkMount /*.jsp default
# Look for index.jsp first, then index.html
DirectoryIndex index2.jsp index.html
# Globally deny access to the WEB-INF directory
<LocationMatch '.*WEB-INF.*'>
# Onderstaande regel kreeg warning 'Useless use of AllowOverride'
# AllowOverride None
deny from all

I'm not 100% sure if I did that correctly, but I think so. So I've got both the JkMount and DirectoryIndex directives included.

bathory 09-20-2010 06:38 AM


JkMount /*.jsp default
This is used to pass he request for a jsp page to a worker named 'default'. If apache still shows the jsp code, it means that it does not do that, or you have to clean your browser's cache.

If you've followed the howto you need also to use the following in apache2.conf:

JkWorkersFile /etc/apache2/
# Where to put jk logs
JkLogFile /var/log/apache2/jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat “[%a %b %d %H:%M:%S %Y] “

Stop both servers and then start tomcat first and apache afterwards.

MHJCuijpers 09-20-2010 07:32 AM

I created /etc/apache2/mods-enabled/jk.conf :

# mod_jk config
# Where to find
JkWorkersFile /etc/apache2/
# Where to put jk logs
JkLogFile /var/log/apache2/jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicate to send SSL KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

Which seems to do exactly the same thing as adding this code directly to the apache2.conf (this was suggested in one of the replies to the howto)

I moved the JkMount lines to /etc/apache2/sites-enabled/000-default

The DirectoryIndex now works correctly (I'm directed to index2.jsp instead of index.html). But, instead of a direct dump of the file, I now get a blank page.

Could this be my sample JSP code? My index2.jsp looks like this:

                <title>JSP Index</title>
                <div>Some text</div>
                <div><%="Some JSP generated text" %></div>

The reason I know the file is being interpreted is that if I approach http://localhost/index.html I still get a valid page, and if I approach http://localhost/index3.php I get an error message - I just get a blank for http://localhost/ and http://localhost/index2.jsp

bathory 09-20-2010 08:36 AM

I'm not familiar with debian, but I guess /etc/apache2/mods-enabled/jk.conf is used just to load the mod_jk module. You better put the JK directives in apache2.conf, or inside the default vhost.
You can check if there is anything logged in /var/log/apache2/jk.log
Also what happens if you move index2.jsp into tomcat ROOT directory?

MHJCuijpers 09-20-2010 09:37 AM

If I look in jk.log I see several messages like this one:

[Tue Aug 10 22:02:20 2010]default localhost 0.001496
I've tried moving the JK directives to apache2.conf and/or 000-default, but to no effect (I get an error message if I try to but them in both the jk.conf and apache2.conf)

Moving the files to the tomcat root sounds like a good idea, but I'm not sure which directory is the tomcat root. I've put both index2.jsp and index.html in /usr/share/tomcat5.5/webapps - still no success (blank pages for both of them by the way - I think this also happened earlier, but I didn't refresh the index.html properly)

Note that in the end I installed the tomcat5.5 package via apt-get, instead of via the download - although I got the download working in the end the package seems to have been improved since the howto was written. I should've mentioned this earlier I guess; I just noted that the latest problems I'm having might be related to the package being messed up (as mentioned in the how-to:

the webapps directory is symlink’d under /var/, which tends to cause problems with Apache->Tomcat configuration.
). I'm going to try to remove the tomcat package installation and replace it with the manual install. I'll report back when I've tried that.

bathory 09-20-2010 10:04 AM


If I look in jk.log I see several messages like this one:

[Tue Aug 10 22:02:20 2010]default localhost 0.001496

This is 10 days old, unless your computer clock is 10 days back

For the default binary tomcat package you need to put the jsp pages in webapps/ROOT/ directory. I guess the blank page is maybe the tomcat 404-error page for debian

MHJCuijpers 09-23-2010 03:08 AM

The computer clock actually is 10 days back; it's a virtual machine and the time sync isn't working properly.

Going to try so things again today; I'll post the results when I get them.

MHJCuijpers 09-23-2010 04:01 AM

webapps/ROOT actually didn't exist, so I created it and added the files there - it works now, thanks for helping me to get started!

I also added NTP so my logfiles won't confuse anyone anymore :)

All times are GMT -5. The time now is 02:31 AM.