Posts Tagged ‘tomcat’

JSP Hello World Howto

Thursday, August 6th, 2009

This can be called a howto of “How can I make a hello world in JSP without unnecessary tools like, Eclipse, struts, servlets, JBoss, etc.?” only you, your text editor, tomcat and of course, your GNU-Linux box.

1. Create a directory anywhere to store your app, let’s create one called “myapp”: mkdir myapp

2. Create your hello.jsp web page: echo ‘<% String hello=”Hello World”; %><%=hello%>’ > myapp/hello.jsp

3. Create your app’s web.xml file, you should have this file under (create it) the WEB-INF directory, under “myapp”:

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
version=”2.4″>
<display-name>Hello World</display-name>
<description>My hello world app.</description>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
</web-app>

4. Install tomcat, for example, in Arch I’ve typed: sudo pacman -Sy tomcat

5. Make your app. available: sudo ln -s /path/to/myapp /opt/tomcat/webapps

6. Start tomcat, for example, in arch I’ve typed: sudo /etc/rc.d/tomcat start

7. Point your browser to: localhost:8080/myapp

Instalación de tomcat 5.5 en debian

Saturday, March 31st, 2007

Me sorprendí cuando al hacer apt-get install tomact5.5 y luego verificar http://localhost:8180 obtuve un error de conexión; enseguida comencé a probar otros puertos, hacer telnet, etc, etc, pero no me podía conectar, entonces fui a buscar el log de tomcat (catalina.out) y resulta que el mismo tenía 0 bytes, pero nunca me dí cuenta que no era un archivo sino un pipe.
Y de que era un pipe me di cuenta cuando comencé a googlear este tema luego de matar y arrancar varias veces el servidor (el stop no funcionaba porque el tomcat nunca arrancaba). Como era un pipe entonces intenté consumir ese pipe con el servidor arrancado: tail -f /var/log/tomcat5.5/catalina.out y al hacer esto el servidor comenzó a funcionar. Al acceder a localhost:8180 obtenía una página en blanco en mi Iceweasel.
Inmediatamente me fui a la página de bugs del paquete en debian y el primer hilo hablaba sobre el tema: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=402603
En uno de los últimos mensajes del hilo alguien brinda dos soluciones, yo opté por la primera, la más fácil, que consta únicamente en cambiar el script de inicialización de tomcat para que use cronolog aplicando el parche que se brinda en el mismo mensaje: patch /etc/init.d/tomcat5.5 tomcat5.5.diff (tuve que instalar cronolog también: apt-get install cronolog)
Luego de patchear y arrancar el tomcat sin problemas, como seguí mirando una página en blanco en el navegador, busqué en google y me di cuenta que también debería instalar los paquetes tomcat5.5-admin y tomcat5.5-webapps y ahí sí pude ver la clásica home de tomcat con el gatito y el logo de apache y todo. En realidad el que trae esa home es el 2º, el primero trae la aplicación de administración.