File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Servlets
Author
Not able to set cookies
Sony Agrawal
Ranch Hand
Joined: Oct 04, 2009
Posts: 143
posted
Feb 22, 2010 02:13:38
0
HI i am trying to learn about cookie ... I am trying to setcookies but not able to...Please let me know the issue... Browser is enable to accept the cookies...
HTML
<form method ='POST' action='bookmark1'> <input type ='text' name ='bookmarkName'><br> <input type= 'submit' value='Iam a button'> </form>
SERVLET
public class bookmark1 extends HttpServlet{ public void doPost (HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException{ Cookie cookie = new Cookie("bookmarkName",(String)req.getParameter("bookmarkName")); cookie.setMaxAge(30*60); System.out.println("ABOUT TO ADD COOKIE"); res.addCookie(cookie); RequestDispatcher View= req.getRequestDispatcher("bookmark2.jsp"); View.forward(req,res); } }
JSP
<% if(null ==request.getCookies() )System.out.println(" NO COOKIES"); if(null !=request.getCookies() )System.out.println("COOKIES ARE PRESENT"); Cookie [] cookieArray= request.getCookies(); for(int i=0; i< cookieArray.length ;i++){ Cookie coo= cookieArray[i]; if (coo.getName().equals("bookmarkName")){ out.println("Your Text:"+ coo.getValue()); break; } } %>
Its printing :"NO COOKIES"
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
2
I like...
posted
Feb 22, 2010 03:40:37
0
Closing thread, continue discussion
here
SCJP 6 | SCWCD 5 |
Javaranch SCJP FAQ
|
SCWCD Links
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Not able to set cookies
Similar Threads
Confusion between Cookie and JSession
Not able to set cookies
Cookies example in HFSJ
Extracting Values From Single Cookie
Testing Cookies
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter