TECHNICALFACILITATION.COM - THE ULTIMATE WEBSPHERE AND JAVA CERTIFICATION GUIDES AND RESOURCES
Google
Download the Completed Solution: CountrySnooper.ear Scroll to the bottom of the page for pertinent code snippets.


Creating a Simple Servlet Using IRAD

This free, multimedia tutorial shows you how to use IBM's Rational Application Developer (IRAD) to create a J2EE project, a Servlet, and a WebSphere Test Server on which you can proudly run your newly birthed Servlet.

If you found something helpful here, please do your part and help support the site. Link to us, buy some books, support our sponsors, tell your developer friends about us, and remember: Happy Java!

package com.examscam.servlet;

import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CountrySnooper extends HttpServlet implements Servlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String country = request.getLocale().getCountry();
if (!country.equals("CA")){
response.getWriter().print("Hey, lets go for a Tim Hortons coffee!");
}
else {
response.getWriter().print("Ugh...Guess we settle for Starbucks");
}
}
}

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 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">
<display-name>
ExamScamWeb</display-name>
<servlet>
<description>
</description>
<display-name>
CountrySnooper</display-name>
<servlet-name>CountrySnooper</servlet-name>
<servlet-class>
com.examscam.servlet.CountrySnooper</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CountrySnooper</servlet-name>
<url-pattern>/CountrySnooper</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

Google
THE ULTIMATE CERTIFICATION AND WEBSPHERE RESOURCES - BUY THEM NOW ON AMAZON
eXTReMe Tracker