• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Session problem in custom tag

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?





 
Sheriff
Posts: 67753
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
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.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
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
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: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
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
 
You can't have everything. Where would you put it?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic