Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session problem in custom tag  RSS feed

 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get an array of cookies in a custom tag. Below is the code, followed by the exception report in the browser. I'm only including the method where the problem is occuring. The exception is being thrown in the line where I'm trying to get an HttpSession (the second line of the method.) Any help or advice out there?





 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are trying to cast a page context instance to a request instance. What's your intent with that? You can't just cast objects into classes they they are not the type of.

If you want to obtain the request, check out the methods on the page context.
 
Chetan Natu
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are trying to get a session, why are you casting it to HttpServletRequest?

It's like getting a round peg and trying to insert into a square hole (or vice versa, as per your preferences)

IF.... you refer to the java documentation, in that case you will observe that the getSession Method returns an object of type HttpSession, which you are trying to cast into HttpServletRequest.

Just for the record, HttpSession and HttpServletRequest are in no way related to each other, you cannot use them as an alternate to each other, as they have totally different structure. Hence you are getting the exception.

and there are lots of things that are wrong with the piece of code and exception that you have sent over. Can't really make any head or tail out of it, unless I get to see the entire code.
 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You are trying to cast a page context instance to a request instance. What's your intent with that? You can't just cast objects into classes they they are not the type of.

If you want to obtain the request, check out the methods on the page context.


Okay, I've made a change, but I'm still having problems. Someone wanted to see the entire code, so here it is, along with the exception.





 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're still trying convoluted casting to achieve.... what? I can't tell.

What's the purpose of this line:
?

In it you are trying to cast an HttpSession to a PageContext? What? Why?

If you want the request, just get it form the page context which you already have. Why all the casting?

Just step away from the casts.

(Btw, pc? Really? Why not pageContext? Keeping the code readable makes it easier to, well, read.)
 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I've got everything working now. I've got the casting down to a reasonable level. Thanks for the help.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!