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.
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.
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.)