jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Raghunandan B" <raghunandan...@gmail.com>
Subject Re:Cactus test case
Date Tue, 12 Feb 2008 03:25:07 GMT
Hi,
How do i write cactus test case to test this servlet


import java.io.*;

import javax.servlet.http.*;
import javax.servlet.*;
import java.net.*;
import java.util.*;



public class SampleServlet extends HttpServlet
{

 public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Session Tracking Example";
    HttpSession session = request.getSession(true);
    String heading;
    Integer accessCount =
      (Integer)session.getAttribute("accessCount");
    if (accessCount == null) {
        accessCount = new Integer(0);
              } else {

        accessCount = new Integer(accessCount.intValue() + 1);
      }

    // Use setAttribute instead of putValue in version 2.2.
    session.setAttribute("accessCount", accessCount);

    out.println(
                "<BODY>\n"+ " <p align=center>"+
        "Session ID" +

                 session.getId() + "<br>"
                +
                "  Creation Time\n" +

                new Date(session.getCreationTime()) + "\n" + "<br>"
                +

                "  Time of Last Access\n" +

                new Date(session.getLastAccessedTime()) + "\n" +"<br>"
                +

                "  Number of Previous Accesses\n" +
                 accessCount + "\n" + "</p>"+

                "</BODY></HTML>");

  }

  /** Handle GET and POST requests identically. */

  public void doPost(HttpServletRequest request,
                     HttpServletResponse response)
      throws ServletException, IOException {
    doGet(request, response);
  }
}



Regards,

Raghu

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message