01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest.webapp.servlets;
05:
06: import java.io.IOException;
07: import java.io.PrintWriter;
08:
09: import javax.servlet.http.HttpServlet;
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12: import javax.servlet.http.HttpSession;
13:
14: public final class SynchronousWriteTestServlet extends HttpServlet {
15: public void doGet(HttpServletRequest request,
16: HttpServletResponse response) throws IOException {
17: HttpSession session = request.getSession(true);
18: response.setContentType("text/html");
19: PrintWriter out = response.getWriter();
20:
21: String serverParam = request.getParameter("server");
22: String dataParam = request.getParameter("data");
23:
24: switch (Integer.parseInt(serverParam)) {
25: case 0:
26: hit0(session, out, dataParam);
27: break;
28: case 1:
29: hit1(session, out, "data" + dataParam);
30: break;
31: default:
32: out.print("unknown value for server param: " + serverParam);
33: }
34: }
35:
36: private void hit1(HttpSession session, PrintWriter out,
37: String attrName) {
38: System.err.println("### hit1: sessionId = " + session.getId());
39: String value = (String) session.getAttribute(attrName);
40: System.err.println(attrName + "=" + value);
41: if (value == null) {
42: out.print(attrName + " is null");
43: } else {
44: out.print(value);
45: }
46: }
47:
48: private void hit0(HttpSession session, PrintWriter out,
49: String dataParam) {
50: System.err.println("### hit0: sessionId = " + session.getId());
51: System.err.println("setAttribute: " + "data" + dataParam);
52: session.setAttribute("data" + dataParam, dataParam);
53: out.print("OK");
54: }
55: }
|