aspose file tools*
The moose likes JSP and the fly likes unable to retrieve cookies & logout properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "unable to retrieve cookies & logout properly" Watch "unable to retrieve cookies & logout properly" New topic
Author

unable to retrieve cookies & logout properly

tushar panda
Ranch Hand

Joined: Feb 16, 2009
Posts: 133
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

Do Right , Fear No Man
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575



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.
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 255

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.

Regards
Salil Verma
tushar panda
Ranch Hand

Joined: Feb 16, 2009
Posts: 133
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

Joined: Sep 06, 2009
Posts: 255

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

Joined: Feb 16, 2009
Posts: 133
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

Joined: Sep 06, 2009
Posts: 255

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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

Why is the code in a JSP in the first place? Modern JSPs should contain no Java code.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to retrieve cookies & logout properly