Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Test for Cookies
12-14-2010, 08:46 AM
Post: #1
Test for Cookies
import javax.servlet.*;
import javax.servlet.http.*;

public class Test4Cookies extends HttpServlet {

private static final Cookie cookie = new Cookie( "hello" , "world" );
private static final String paramName = "foo";
private static final String successURI = "/success.htm";
private static final String failureURI = "/failure.htm";

public void doPost(HttpServletRequest req, HttpServletResponse res) {
if ( req.getParameter( paramName ) == null ) {
res.addCookie( cookie );
res.sendRedirect(req.getRequestURI() +"?"+ paramName +"=bar" );
}
else {
res.sendRedirect
(( req.getCookies().length == 0 ) ? failureURI : successURI
)
}

public void doGet(HttpServletRequest req, HttpServletResponse res) {
doPost(req, res);
}
}
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:



Send your comments, Suggestions or Queries regarding this site at info@tutorials4u.net

Copyright © 2010 Tutorials4u.net All Rights Reserved