Please send questions to
st10@humboldt.edu .
// simple variation on HelloName (to see if I
// can do it...!) --- let user specify a particular name!
//
// try to call it using
// http://sorrel.humboldt.edu:8895/jservf/st10/st10GreetMe?username=Sharon
// (or substituting the user name of your choice, of course!)
//
// modifications are from "Java Examples in a Nutshell", Flanagan,
// p. 462 (and comments marked [JEN] are from there)
//
// comments marked with [SST] are quoted from the
// first simple Servlet example in the Sun
// Servlets Tutorial, available at
// http://java.sun.com/docs/books/tutorial/servlets/overview/simple.html
//
// assumptions: to compile, must set certain environment variables!
//
// last modified: 4-30-01
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
// notice that you extend HttpServlet...
public class st10GreetMe extends HttpServlet
{
// [SST] "Handle the HTTP GET method by building a
// simple web page."
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
String name;
// [JEN] "see if the username is specified by
// the request"
name = request.getParameter("username");
// [JEN] "If not, look in the session object. The web
// server or servlet container performs session
// tracking automatically for the servlet, and
// associates a HttpSession object with each session"
if (name == null)
{
name = (String)request.getSession().getValue("username");
}
// [JEN] and use a default name, otherwise!
if (name == null)
{
name = "whoever you are";
}
// [SST] "set content type and other response
// header fields first"
response.setContentType("text/html");
// [SST] "then write the data of the response"
out = response.getWriter();
out.println("<HTML><BODY>");
out.println("<H2>Greetings and Salutations, oh " + name + "</H2>");
out.print("<p><a href=");
out.print("\"http://www.humboldt.edu/~st10/s01cis480j\">");
out.println("Click here</a> to reach CIS 480 web page.</p>");
out.println("</BODY></HTML>");
} // doGet
} // HelloServlet