MCPcopy Index your code
hub / github.com/apache/tomcat / doGet

Method doGet

webapps/examples/WEB-INF/classes/SessionExample.java:44–156  ·  view source on GitHub ↗
(HttpServletRequest request, HttpServletResponse response)

Source from the content-addressed store, hash-verified

42
43
44 @Override
45 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
46 ResourceBundle rb = ResourceBundle.getBundle("LocalStrings", request.getLocale());
47
48 response.setContentType("text/html");
49 response.setCharacterEncoding("UTF-8");
50
51 PrintWriter out = response.getWriter();
52 out.println("<!DOCTYPE html><html>");
53 out.println("<head>");
54 out.println("<meta charset=\"UTF-8\" />");
55
56
57 String title = rb.getString("sessions.title");
58 out.println("<title>" + title + "</title>");
59 out.println("</head>");
60 out.println("<body bgcolor=\"white\">");
61
62 out.println("<a href=\"../sessions.html\">");
63 out.println(
64 "<img src=\"../images/code.gif\" height=24 " + "width=24 align=right border=0 alt=\"view code\"></a>");
65 out.println("<a href=\"../index.html\">");
66 out.println(
67 "<img src=\"../images/return.gif\" height=24 " + "width=24 align=right border=0 alt=\"return\"></a>");
68
69 out.println("<h3>" + title + "</h3>");
70
71 HttpSession session = request.getSession(true);
72 out.println(rb.getString("sessions.id") + " " + session.getId());
73 out.println("<br>");
74 out.println(rb.getString("sessions.created") + " ");
75 out.println(new Date(session.getCreationTime()) + "<br>");
76 out.println(rb.getString("sessions.lastaccessed") + " ");
77 out.println(new Date(session.getLastAccessedTime()));
78
79 // Count the existing attributes
80 int sessionAttributeCount = 0;
81 Enumeration<String> names = session.getAttributeNames();
82 while (names.hasMoreElements()) {
83 names.nextElement();
84 sessionAttributeCount++;
85 }
86
87 String dataName = request.getParameter("dataname");
88 String dataValue = request.getParameter("datavalue");
89 if (dataName != null) {
90 if (dataValue == null) {
91 session.removeAttribute(dataName);
92 sessionAttributeCount--;
93 } else if (sessionAttributeCount < SESSION_ATTRIBUTE_COUNT_LIMIT) {
94 session.setAttribute(dataName, dataValue);
95 sessionAttributeCount++;
96 } else {
97 out.print("<p> Session attribute [");
98 out.print(HTMLFilter.filter(dataName));
99 out.print("] not added as there are already "+ SESSION_ATTRIBUTE_COUNT_LIMIT + " attributes in the ");
100 out.println("session. Delete an attribute before adding another.");
101 }

Callers 1

doPostMethod · 0.95

Calls 15

getIdMethod · 0.95
getCreationTimeMethod · 0.95
getLastAccessedTimeMethod · 0.95
getAttributeNamesMethod · 0.95
removeAttributeMethod · 0.95
setAttributeMethod · 0.95
filterMethod · 0.95
getAttributeMethod · 0.95
encodeMethod · 0.95
getLocaleMethod · 0.65
setContentTypeMethod · 0.65
setCharacterEncodingMethod · 0.65

Tested by

no test coverage detected