public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { HttpSession sess = req.getSession(false); sess.invalidate(); System.out.println("Session Closed"); res.sendRedirect("index.html"); }
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); Enumeration values = req.getParameterNames(); String name = ""; String value = ""; String id = ""; while (values.hasMoreElements()) { name = ((String) values.nextElement()).trim(); value = req.getParameter(name).trim(); if (name.equals("id")) id = value; } if (url.equals("")) { url = getServletContext().getInitParameter("url"); cas_url = getServletContext().getInitParameter("cas_url"); } HttpSession session = null; session = req.getSession(false); if (session != null) { session.invalidate(); } res.sendRedirect(cas_url); return; }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { // 로그아웃할거임 HttpSession session = request.getSession(false); // 세션세션 response.setContentType("text/html;charset=utf-8"); // 한글깨짐방지 session.invalidate(); // 세션날려버려 response.sendRedirect("../index.jsp"); // 돌아감 return; }
/** * this is the main method of the servlet that will service all get requests. * * @param request HttpServletRequest * @param responce HttpServletResponce */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = null; try { try { session = request.getSession(true); } catch (Exception e) { Log.error(e, "PingSession2.doGet(...): error getting session"); // rethrow the exception for handling in one place. throw e; } // Get the session data value Integer ival = (Integer) session.getAttribute("sessiontest.counter"); // if there is not a counter then create one. if (ival == null) { ival = new Integer(1); } else { ival = new Integer(ival.intValue() + 1); } session.setAttribute("sessiontest.counter", ival); // if the session count is equal to five invalidate the session if (ival.intValue() == 5) { session.invalidate(); } try { // Output the page response.setContentType("text/html"); response.setHeader("SessionTrackingTest-counter", ival.toString()); PrintWriter out = response.getWriter(); out.println( "<html><head><title>Session Tracking Test 2</title></head><body><HR><BR><FONT size=\"+2\" color=\"#000066\">HTTP Session Test 2: Session create/invalidate <BR></FONT><FONT size=\"+1\" color=\"#000066\">Init time: " + initTime + "</FONT><BR><BR>"); hitCount++; out.println( "<B>Hit Count: " + hitCount + "<BR>Session hits: " + ival + "</B></body></html>"); } catch (Exception e) { Log.error(e, "PingSession2.doGet(...): error getting session information"); // rethrow the exception for handling in one place. throw e; } } catch (Exception e) { // log the excecption Log.error(e, "PingSession2.doGet(...): error."); // set the server responce to 500 and forward to the web app defined error page response.sendError(500, "PingSession2.doGet(...): error. " + e.toString()); } } // end of the method
/** @service the servlet service request. called once for each servlet request. */ public void service(HttpServletRequest servReq, HttpServletResponse servRes) throws IOException { String name; String value[]; String val; servRes.setHeader("AUTHORIZATION", "user fred:mypassword"); ServletOutputStream out = servRes.getOutputStream(); HttpSession session = servReq.getSession(true); session.setAttribute("timemilis", new Long(System.currentTimeMillis())); if (session.isNew()) { out.println("<p> Session is new "); } else { out.println("<p> Session is not new "); } Long l = (Long) session.getAttribute("timemilis"); out.println("<p> Session id = " + session.getId()); out.println("<p> TimeMillis = " + l); out.println("<H2>Servlet Params</H2>"); Enumeration e = servReq.getParameterNames(); while (e.hasMoreElements()) { name = (String) e.nextElement(); value = servReq.getParameterValues(name); out.println(name + " : "); for (int i = 0; i < value.length; ++i) { out.println(value[i]); } out.println("<p>"); } out.println("<H2> Request Headers : </H2>"); e = servReq.getHeaderNames(); while (e.hasMoreElements()) { name = (String) e.nextElement(); val = (String) servReq.getHeader(name); out.println("<p>" + name + " : " + val); } try { BufferedReader br = servReq.getReader(); String line = null; while (null != (line = br.readLine())) { out.println(line); } } catch (IOException ie) { ie.printStackTrace(); } session.invalidate(); }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { HttpSession session = request.getSession(); String food = (String) session.getAttribute("FOOD"); String animal = request.getParameter("ANIMAL"); session.invalidate(); response.setContentType("text/html;charset=euc-kr"); PrintWriter out = response.getWriter(); out.println("<HEAD><TITLE>성격 테스트</TITLE></HEAD>"); out.println("<BODY>"); out.println("<H3>성격 테스트</H3>"); out.printf("당신은 %s와 %s를 좋아하는 성격입니다.", food, animal); out.println("</BODY>"); out.println("</HTML>"); }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // tengo que eliminar al usuario de la sesión HttpSession session = request.getSession(false); String next = "/error.html"; if (session != null) { User user = (User) session.getAttribute("user"); session.removeAttribute("user"); session.invalidate(); next = "/login.html"; // JSP destino } RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(next); dispatcher.forward(request, response); }
/** * Logout a Trade User Dispatch to the Trade Welcome JSP for display * * @param userID The User to logout * @param ctx the servlet context * @param req the HttpRequest object * @param resp the HttpResponse object * @param results A short description of the results/success of this web request provided on the * web page * @exception javax.servlet.ServletException If a servlet specific exception is encountered * @exception javax.io.IOException If an exception occurs while writing results back to the user */ void doLogout(ServletContext ctx, HttpServletRequest req, HttpServletResponse resp, String userID) throws ServletException, IOException { String results = ""; try { tAction.logout(userID); } catch (java.lang.IllegalArgumentException e) { // this is a user error so I will // forward them to another page, at the end of the page. req.setAttribute("results", results + "illegal argument:" + e.getMessage()); // log the exception with an error level of 3 which means, handled exception but would // invalidate a automation run Log.error( e, "TradeServletAction.doLogout(...)", "illegal argument, information should be in exception string", "treating this as a user error and forwarding on to a new page"); } catch (Exception e) { // log the exception and foward to a error page Log.error( e, "TradeServletAction.doLogout(...):", "Error logging out" + userID, "fowarding to an error page"); // set the status_code to 500 throw new ServletException( "TradeServletAction.doLogout(...)" + "exception logging out user " + userID, e); } HttpSession session = req.getSession(); if (session != null) { session.invalidate(); } Object o = req.getAttribute("TSS-RecreateSessionInLogout"); if (o != null && ((Boolean) o).equals(Boolean.TRUE)) { // Recreate Session object before writing output to the response // Once the response headers are written back to the client the opportunity // to create a new session in this request may be lost // This is to handle only the TradeScenarioServlet case session = req.getSession(true); } requestDispatch(ctx, req, resp, userID, TradeConfig.getPage(TradeConfig.WELCOME_PAGE)); }
/** * Creates a db connecton. * * @return true if OK, false if there's a problem */ private boolean createDbConnection( HttpSession session, HttpServletRequest req, HttpServletResponse res) throws Exception { // At this point a driver and connection may already be set // up. So here it first tests if a connection can be made. // If not, set params up, and test the setup. if (ConnManager.getConn() == null) { ConnManager.getInstance() .setLoginParams( session.getAttribute("dbtDbDriver"), session.getAttribute("dbtDbUrl"), session.getAttribute("dbtDbUser"), session.getAttribute("dbtDbPassword")); if (ConnManager.getConn() == null) { Util.putMessagePage(res, "Cannot login to DBT database"); // Invalidates the session in case connection is "stuck" in error session.invalidate(); return false; } } return true; }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); boolean clear = request.getParameter("clear") != null; if (clear) session.invalidate(); else { String name = request.getParameter("Name"); String value = request.getParameter("Value"); if (name != null && value != null) session.setAttribute(name, value); } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html><head><title>Show Session</title></head><body>"); if (clear) out.println("<h1>Session Cleared:</h1>"); else { out.println("<h1>In this session:</h1><ul>"); Enumeration names = session.getAttributeNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); out.println("<li>" + name + " = " + session.getAttribute(name)); } } out.println( "</ul><p><hr><h1>Add String</h1>" + "<form method=\"POST\" action=\"" + request.getRequestURI() + "\">" + "Name: <input name=\"Name\" size=20><br>" + "Value: <input name=\"Value\" size=20><br>" + "<br><input type=\"submit\" value=\"Submit\">" + "<input type=\"submit\" name=\"clear\" value=\"Clear\"></form>"); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean orderCompleted = true; // Get the user's session and shopping cart HttpSession session = request.getSession(true); ResourceBundle messages = (ResourceBundle) session.getAttribute("messages"); ShoppingCart cart = (ShoppingCart) session.getAttribute("cart"); if (cart == null) { cart = new ShoppingCart(); session.setAttribute("cart", cart); } // Update the inventory try { utx.begin(); bookDB.buyBooks(cart); utx.commit(); } catch (Exception ex) { try { utx.rollback(); } catch (Exception e) { System.out.println("Rollback failed: " + e.getMessage()); } System.err.println(ex.getMessage()); orderCompleted = false; } // Payment received -- invalidate the session session.invalidate(); // set content type header before accessing the Writer response.setContentType("text/html"); response.setBufferSize(8192); PrintWriter out = response.getWriter(); // then write the response out.println( "<html>" + "<head><title>" + messages.getString("TitleReceipt") + "</title></head>"); // Get the dispatcher; it gets the banner to the user RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/banner"); if (dispatcher != null) { dispatcher.include(request, response); } if (orderCompleted) { out.println("<h3>" + messages.getString("ThankYou") + request.getParameter("cardname") + "."); } else { out.println("<h3>" + messages.getString("OrderError")); } out.println( "<p> <p><strong><a href=\"" + response.encodeURL(request.getContextPath()) + "/bookstore\">" + messages.getString("ContinueShopping") + "</a> " + "</body></html>"); out.close(); }
public void processRequest(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { HttpSession session = req.getSession(true); root = req.getContextPath(); String addButton = req.getParameter("addButton"); try { session = req.getSession(true); if (session.isNew()) { session.invalidate(); res.setContentType("text/html;charset=UTF-8"); PrintWriter out = res.getWriter(); out.println( (new StringBuilder()) .append("<html><HEAD><META HTTP-EQUIV='Refresh' CONTENT='0; URL=") .append(root) .append("/AID'/></HEAD></html>") .toString()); out.close(); } } catch (IllegalStateException e) { res.sendRedirect((new StringBuilder()).append(root).append("/AID").toString()); } String originalQuery = (String) session.getAttribute("query"); if (addButton != null) { String newQueryTerms[] = (String[]) req.getParameterValues("newQueryTerms"); if ((newQueryTerms == null) || (newQueryTerms.length == 0)) { res.sendRedirect( res.encodeURL( root.concat( (new StringBuilder()) .append("/AID?query=") .append(originalQuery.replaceAll("\\s+", "+")) .toString()))); } else { String newQuery = originalQuery.replaceAll("\\s+", "+"); for (int i = 0; i < newQueryTerms.length; i++) { newQuery = (new StringBuilder()) .append(newQuery) .append("+") .append(newQueryTerms[i]) .toString(); } res.sendRedirect( res.encodeURL( root.concat( (new StringBuilder()).append("/AID?query=").append(newQuery).toString()))); } } else { String spellMatrix[] = (String[]) session.getAttribute("retSpellSuggestions"); String termsInQuery[] = (String[]) session.getAttribute("termsInQuery"); String wordnetMatrix[][] = (String[][]) session.getAttribute("retWordnetSynsMatrix"); String synonymMatrix[][] = (String[][]) session.getAttribute("retSynsMatrix"); String onlineSynMatrix[][] = (String[][]) session.getAttribute("onlineSynMatrix"); res.setContentType("text/html;charset=UTF-8"); PrintWriter out = res.getWriter(); out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"); out.println("<html>"); out.println("<head>"); out.println("<title>AID Search interface</title>"); out.println( (new StringBuilder()) .append("<style type='text/css'>@import url(") .append(root) .append("/css/qckcss.css);") .toString()); out.println("</style>"); out.println( (new StringBuilder()) .append("<link REL=\"SHORTCUT ICON\" HREF=\"") .append(root) .append("/images/favicon.ico\">") .toString()); out.println( (new StringBuilder()) .append("<script type=\"text/javascript\" src=\"") .append(root) .append("/javascript/overlib.js\">") .toString()); out.println("<!-- bla -->"); out.println("</script>"); out.println("</head>"); out.println( (new StringBuilder()) .append("<body bgcolor=white background=\"") .append(root) .append("/images/background.gif\">") .toString()); out.println("<div id=\"AIDfp\">"); out.println("<a name=\"top\"/>"); out.println(" <table border=\"0\" width=600>"); out.println("<tr><td colspan=3>"); out.println("<table>"); out.println("\t<tr valign=\"top\" bgcolor=white><td class=\"navtext\">"); out.println("\t<div id=\"navlinks\">"); out.println( (new StringBuilder()) .append("\t\t<img src=\"") .append(root) .append( "/images/top.png\" width=\"709\" height=\"200\" border=\"0\"><!-- bla --> </img>") .toString()); out.println( (new StringBuilder()) .append( "\t\t<div style=\"position: relative;top: -55px;margin-left: 15px;\"><a href=\"") .append(root) .append("/\">Home</a></div>") .toString()); out.println( "\t\t<div style=\"position: relative;top: -71px;margin-left: 180px;\">Concept Finder</div>"); out.println( "\t\t<div style=\"position: relative;top: -87px;margin-left: 410px;\">Search Details</div>"); out.println( "\t\t<div style=\"position: relative;top: -103px;margin-left: 620px;\">History</div>"); out.println("</div></td></tr></table>"); out.println("</td></tr>"); out.println( (new StringBuilder()) .append(" <form name=\"selectionForm\" method=\"get\" action=\"") .append(res.encodeURL(req.getRequestURI())) .append("\">") .toString()); out.println(" <tr>"); out.println(" <td width=33% class='resultItemCenter'>"); if (synonymMatrix != null) { out.println(" Found index-specific syonyms:<br>"); out.println(" <select name='newQueryTerms' multiple>"); for (int i = 0; i < synonymMatrix.length; i++) { for (int j = 0; j < synonymMatrix[i].length; j++) { if (synonymMatrix[i][j] != null) { out.println( (new StringBuilder()) .append(" <option value='") .append(synonymMatrix[i][j]) .append("'>") .append(synonymMatrix[i][j]) .append("</option>") .toString()); } } } out.println(" </select>"); } out.println(" </td>"); out.println(" <td width=33% class='resultItemCenter'>"); if (wordnetMatrix != null) { out.println(" Found Wordnet syonyms:<br>"); out.println(" <select name='newQueryTerms' multiple>"); for (int i = 0; i < wordnetMatrix.length; i++) { for (int j = 0; j < wordnetMatrix[i].length; j++) { if (wordnetMatrix[i][j] != null) { out.println( (new StringBuilder()) .append(" <option value='") .append(wordnetMatrix[i][j]) .append("'>") .append(wordnetMatrix[i][j]) .append("</option>") .toString()); } } } out.println(" </select>"); } out.println(" </td>"); out.println(" <td width=33% class='resultItemCenter'>"); if (onlineSynMatrix != null) { out.println(" Found online acronyms:<br>"); out.println(" <select name='newQueryTerms' multiple>"); for (int i = 0; i < onlineSynMatrix.length; i++) { for (int j = 0; j < onlineSynMatrix[i].length; j++) { if (onlineSynMatrix[i][j] != null) { out.println( (new StringBuilder()) .append(" <option value='") .append(onlineSynMatrix[i][j]) .append("'>") .append(onlineSynMatrix[i][j]) .append("</option>") .toString()); } } } out.println(" </select>"); } out.println(" </td> </tr>"); out.println(" <tr>"); out.println(" <td class='resultItemCenter' width=100% colspan=3>"); out.println(" <hr/>"); out.println(" </td>"); out.println(" </tr>"); out.println(" <tr>"); out.println(" <td class='resultItemCenter' width=100% colspan=3>"); out.println(" <input type=submit name=\"addButton\" value=\"Add\">"); out.println(" </td>"); out.println(" </tr>"); out.println(" </form>"); out.println(" </table>"); out.println("<div id=\"footer\">"); out.println("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">"); out.println("<tr>"); out.println( (new StringBuilder()) .append("<td width=\"1%\"><img src=\"") .append(root) .append( "/images/footer-leftcurve.gif\" width=\"10\" height=\"31\" border=\"0\"/></td>") .toString()); out.println("<td width=\"98%\" bgcolor=\"#\" class=\"footertext\">"); out.println("<a href=\"#top\">Top</a>"); out.println(" |\t\t"); out.println( (new StringBuilder()) .append("<a href=\"") .append(root) .append("/synonym\">Synonym client</a>") .toString()); out.println(" |\t\t"); out.println("<a href=\"http://www.vl-e.nl\">Vl-e</a>"); out.println("</td>"); out.println( (new StringBuilder()) .append("<td width=\"1%\"><img src=\"") .append(root) .append( "/images/footer-rightcurve.gif\" width=\"10\" height=\"31\" border=\"0\"/></td>") .toString()); out.println("</tr>"); out.println("</table>"); out.println("</div>"); out.println("</div>"); out.println("</body>"); out.println("</html>"); out.close(); } }
/** Cracks the command and invokes the appropriate next screen */ public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try { // Sets up session tracking ServletContext context = getServletContext(); HttpSession session = req.getSession(); // Gets command, which says what button was pressed String command = req.getParameter("command"); if (command == null) { Util.putMessagePage(res, "Please go back and use a button"); return; } // "Exit" invalidates the session if (command.equals("Exit")) { Util.exitSession(session, res); return; } // "Relogin" invalidates the session and starts over if (command.equals("Relogin")) { session.invalidate(); RequestDispatcher dispatcher = context.getRequestDispatcher(Util.BASE + "index.jsp"); dispatcher.forward(req, res); return; } // At this point the session may be new, or may be already // validated. If session is not valid, or if a login was // specified, do a dbt database login, and validate the // user's login. if (!Util.isSessionValid(session, null) || req.getParameter("Username") != null) { if (!createDbConnection(session, req, res)) return; if (!validateLogin(session, req, res)) return; } // Shows the DBT_DB records if (command.indexOf("Databases") > -1) { RequestDispatcher dispatcher = context.getRequestDispatcher(Util.BASE + "ShowDbs.jsp"); dispatcher.forward(req, res); return; } // Displays all the history records if (command.indexOf("History") > -1) { RequestDispatcher dispatcher = context.getRequestDispatcher(Util.BASE + "ShowHistory.jsp"); dispatcher.forward(req, res); return; } // Changes the user's password if (command.indexOf("Password") > -1) { RequestDispatcher dispatcher = context.getRequestDispatcher(Util.BASE + "ChangePassword.jsp"); dispatcher.forward(req, res); return; } // Performs admin functions if (command.indexOf("Admin") > -1) { RequestDispatcher dispatcher = context.getRequestDispatcher(Util.BASE + "AdminFnc.jsp"); dispatcher.forward(req, res); return; } Util.putMessagePage( res, "<p>Dbtracker internal error<p>Unknown command in " + getServletInfo()); } catch (ServletException e) { throw e; } catch (IOException e) { throw e; } catch (Throwable t) { Util.putExceptionPage(res, t); } }