<%@ page import="java.io.*" %> <% if (request.getParameter ("action") == null) { %> Internet Psychologist

Welcome to the Internet Psychologist!

The psychologist can see you now...please enter your name and click the Introduce button.

" method="POST">

Please enter your name:

<% } else if (request.getParameter ("action").equals ("goto_question")) { createResponsePage (request, response); } else if (request.getParameter ("action").equals ("goto_statistics")) { createStatisticsPage (request, response); } else { /* An incorrect action! */ %> Internet Psychologist

Sorry, the Psychologist is having a bad day.

The action was: <%= request.getParameter ("action") %>

<% } %> <%! /* Various private methods to do the work. */ private void createStatisticsPage (HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { HttpSession session = request.getSession(); PrintWriter out = response.getWriter(); out.println (""); out.println (""); out.println ("Internet Psychologist Statistics"); out.println (""); out.println (""); out.println ("

Your Psychologist Statistics:

"); out.println ("

You have made "); Integer num = (Integer) session.getAttribute ("num_statements"); if (num != null) out.println (num); else out.println ("0"); out.println (" statements to the psychologist.

"); out.println ("
"); out.println (""); out.println (""); out.println ("
"); out.println (""); out.println (""); } private void createResponsePage (HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { HttpSession session = request.getSession(); PrintWriter out = response.getWriter(); out.println (""); out.println (""); out.println ("Internet Psychologist"); out.println (""); out.println (""); out.println ("

Hello, "); String name = request.getParameter ("name"); if (name == null) name = (String) session.getAttribute ("name"); else session.setAttribute ("name", name); out.println (name + "

"); if (request.getParameter ("statement") == null) { out.println ("

Enter a statement in the edit field below about "); out.println ("how you are feeling.

"); } else { out.println ("

" + processStatement (request.getParameter ("statement"))); out.println ("

"); out.println ("

If you would like to continue talking with the psychologist"); out.println (" enter another statement

"); Integer num = (Integer) session.getAttribute ("num_statements"); if (num != null) session.setAttribute("num_statements", new Integer (num.intValue() + 1)); else session.setAttribute("num_statements", new Integer (1)); } out.println ("
"); out.println ("

Statement:

"); out.println (""); out.println (""); out.println ("
"); out.println ("
"); out.println (""); out.println (""); out.println ("
"); out.println (""); out.println (""); } private String processStatement (String statement) { return "How do you feel when you say, \"" + statement + "\""; } %>