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

Method doGet

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

Source from the content-addressed store, hash-verified

36 private static final long serialVersionUID = 1L;
37
38 @Override
39 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
40 ResourceBundle rb = ResourceBundle.getBundle("LocalStrings", request.getLocale());
41
42 String cookieName = request.getParameter("cookiename");
43 String cookieValue = request.getParameter("cookievalue");
44 Cookie aCookie = null;
45 if (cookieName != null && cookieValue != null) {
46 aCookie = new Cookie(cookieName, cookieValue);
47 aCookie.setPath(request.getContextPath() + "/");
48 response.addCookie(aCookie);
49 }
50
51 response.setContentType("text/html");
52 response.setCharacterEncoding("UTF-8");
53
54 PrintWriter out = response.getWriter();
55 out.println("<!DOCTYPE html><html>");
56 out.println("<head>");
57 out.println("<meta charset=\"UTF-8\" />");
58
59 String title = rb.getString("cookies.title");
60 out.println("<title>" + title + "</title>");
61 out.println("</head>");
62 out.println("<body bgcolor=\"white\">");
63
64 out.println("<a href=\"../cookies.html\">");
65 out.println(
66 "<img src=\"../images/code.gif\" height=24 " + "width=24 align=right border=0 alt=\"view code\"></a>");
67 out.println("<a href=\"../index.html\">");
68 out.println(
69 "<img src=\"../images/return.gif\" height=24 " + "width=24 align=right border=0 alt=\"return\"></a>");
70
71 out.println("<h3>" + title + "</h3>");
72
73 Cookie[] cookies = request.getCookies();
74 if ((cookies != null) && (cookies.length > 0)) {
75 HttpSession session = request.getSession(false);
76 String sessionId = null;
77 if (session != null) {
78 sessionId = session.getId();
79 }
80 out.println(rb.getString("cookies.cookies") + "<br>");
81 for (Cookie cookie : cookies) {
82 String cName = cookie.getName();
83 String cValue = cookie.getValue();
84 out.print("Cookie Name: " + HTMLFilter.filter(cName) + "<br>");
85 out.println(" Cookie Value: " + HTMLFilter.filter(CookieFilter.filter(cName, cValue, sessionId)) +
86 "<br><br>");
87 }
88 } else {
89 out.println(rb.getString("cookies.no-cookies"));
90 }
91
92 if (aCookie != null) {
93 out.println("<P>");
94 out.println(rb.getString("cookies.set") + "<br>");
95 out.print(rb.getString("cookies.name") + " " + HTMLFilter.filter(cookieName) + "<br>");

Callers 1

doPostMethod · 0.95

Calls 15

setPathMethod · 0.95
getIdMethod · 0.95
filterMethod · 0.95
filterMethod · 0.95
getLocaleMethod · 0.65
getParameterMethod · 0.65
getContextPathMethod · 0.65
addCookieMethod · 0.65
setContentTypeMethod · 0.65
setCharacterEncodingMethod · 0.65
getWriterMethod · 0.65
getStringMethod · 0.65

Tested by

no test coverage detected