Simple webapp with JBoss (JSP/Servlet/HTML)
So, I downloaded this JBoss 5 beta 2 zip file, and I can run a simple webapp deployed as a war file. [ From here on, it is assumed that jboss is extracted to /projects/jboss, or in other words /projects/jboss is the JBOSS_HOME directory ] The structure for the webapp is as follows
- META-INF/MANIFEST.MF
- index.jsp
- WEB-INF/web.xml
- WEB-INF/classes/TestApp.class
META-INF/MANIFEST.MF
Manifest-Version: 1.0 Created-By: 1.5.0_02 (Sun Microsystems Inc.)
index.jsp { not upto w3c standards :( }
<html> <head><title>Welcome</title></head> <body>Hi!</body> </html>
WEB-INF/web.xml (maps *.html request to the response from the Servlet)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
'http://java.sun.com/dtd/web-app_2_3.dtd'><web-app>
<servlet>
<servlet-name>testappserv</servlet-name>
<servlet-class>TestApp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testappserv</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
WEB-INF/classes/TestApp.class is compiled from TestApp.java
(needs /projects/jboss/server/default/lib/javax.servlet.jar)
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TestApp extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String data = req.getParameter("data");
PrintWriter out = resp.getWriter();
if(data == null) {
out.println("success");
} else {
out.println(data);
}
out.close();
}
}
That’s all! But even four is enough :(
- Package (zip) them as mytestapp.war
- Place into /projects/jboss/server/default/deploy/
- Start jboss using /projects/jboss/bin/run.sh
- Let the server start (wait approximately a minute)
- See the response of http://localhost:8080/mytestapp
(The index.jsp must be the response) - See the response of http://localhost:8080/mytestapp/random.html
(It must give invoke and get the response from the servlet) - Stop jboss using /projects/jboss/bin/shutdown.sh -S
December 9, 2007