• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to retrieve cookies & logout properly

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all ,
i wrote the codes so that it can login as well as logout , but the problem is the cookies are not being retrieved.
codes :
books.jsp :



cookie setting class :



remove cookie class(uncookie.java)



now iam unable to retrieve the "regcookie" as mentioned in comments in first code , is there a problem in setting cookies for the session.
when checked for cookies i found that there are 2 cookies in browser "JSESSIONID" and "regcookie".but when iretrieve iget only "JSESSIONID"
not the one i had set and morever i get the length of cookie set as "1" but i should have got "2" .
i think may be the cookie setting and retrieving is not correct .

waiting for reply
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


well, [i am not sure]. probably you need to set setMaxAge(8) on Cookie. if you ignore this(or setting negative value),the cookie is available only till the current session get expire.
 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Tushar,

I could not find how you were calling regfound servlet. As we know that cookie is being set on this so this servlet must be called before books.jsp only. I tweaked the code a bit and added a doGet method in regfound servlet created web.xml entry for same.

After it, I called this servlet from browser first and then books.jsp. In this case I was returning the value of <%=cf%> = true.




Kindly call this servlet (after including doGet method) first and then jsp. This would definitely work at your end as well.
 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Salil Vverma ,
but i cannot understand a couple of things & have got some errors . please clear me.

Salil Vverma wrote:servlet must be called before books.jsp only.


i have called it , as i have already mentioned in post above that i can see two cookies "JSESSIONID" and "regcookie" in browser it means cookie setting is correct(may be its not set according to requirement)

Salil Vverma wrote:I added a doGet method in regfound servlet


explain me why shall i need this i am already passng my data in "post" method.

Salil Vverma wrote:created web.xml entry for same.


well i shouldnot ask this , but how to set this

Salil Vverma wrote:private static final long serialVersionUID = 1L;


may be "JSESSIONID" should be used instead of "serialVersionUID" because i donot see "serialVersionUID" beaing used at any point of program.

Salil Vverma wrote:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(req, resp);
}
}


i am not using "get" method to pass data so what i am overriding .

please clarify the doubts i am stuck here for last 2 days .

friend at last i got these errors :


i hope the next post will solve my problem

-- TUSHAR
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Tushar,

i have already mentioned in post above that i can see two cookies "JSESSIONID" and "regcookie" in browser it means cookie setting is correct(may be its not set according to requirement)



If you are sure that your previous existing set up was working fine and setting up the cookies . Kindly update the books.jsp file and let me know the output.



at my end the output is as follows -

cookie's name regcookie cookie's value = qwerty
we found regcookie
cookie's name JSESSIONID cookie's value = 20529e81f3329a5074695bc3c171d

 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Salil Vverma wrote:Hey Tushar,
let me know the output.



here is the output after changing the code :



one more thing : the code works in servlet but not in jsp .
a bit confused the same code works for you ,yet for me its doesn't . is it a problem with my browser or something else.
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey tushar,

one more thing : the code works in servlet but not in jsp .



jsp is converted to servlet before it is processed. Just try to identify what the difference would be in the code between the servlet which is working at your end and in the servlet when it would have been converted to servlet.

You might need to check whether the servlet which is setting the cookie is being called before you call this jsp.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is the code in a JSP in the first place? Modern JSPs should contain no Java code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic