Java Reference
In-Depth Information
extension, but typically use .jar or .war to avoid confusion. We'll call our WAB fancy-
foods.web_1.0.0.jar.
WEB DEPLOYMENT DESCRIPTORS
Let's start with the deployment descriptor. Listing 2.1 shows the web.xml file for the
web application. It's a typical web.xml file whose syntax will be reassuringly familiar to
everyone who has developed Java EE web applications. The web application has one
servlet, whose class is fancyfoods.web.SayHello .
Listing 2.1
The WEB-INF/web.xml file
<web-app>
<servlet>
<servlet-name>SayHello</servlet-name>
<servlet-class>fancyfoods.web.SayHello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SayHello</servlet-name>
<url-pattern>/SayHello</url-pattern>
</servlet-mapping>
</web-app>
A SIMPLE SERVLET
The servlet class SayHello is also exactly the same as it would be in a WAR . Listing 2.2
shows the source. There's one method, which—unsurprisingly—issues a greeting to a
user.
A servlet with backing
class SayHello
URL is
SayHello
Listing 2.2
The SayHello.java file
package fancyfoods.web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class SayHello extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOExcepti on {
PrintWriter writer = response.getWriter();
writer.append("Hello valued customer!");
Write to response's
PrintWriter
}
}
So far, so familiar. It's perhaps a bit anticlimactic that writing a WAB is so similar to writing
a WAR in some respects, but this is one of the strengths of the enterprise OSG i program-
ming model—it's like existing programming models, only better. The differences
between WAB s and WAR s start to become obvious when you look at the manifest file.
 
Search WWH ::




Custom Search