Posts Tagged ‘jsp’

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