jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes non-HTTP request or response Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "non-HTTP request or response Exception" Watch "non-HTTP request or response Exception" New topic
Author

non-HTTP request or response Exception

Med Shabe
Ranch Hand

Joined: May 08, 2001
Posts: 84
I'm attempting to process a request and send it to the appropriate JSP file using the folowing syntax:

But I get a non-HTTP request or response Exception as soon as I hit the forwarding line. I checked the method and it is POST. However if I change the forward to include action it works. I've read the API doc for the forward and the include but can't tell where and when to use what.
Any and every thoughts are appreciated
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Med
The _jspService method requires an HttpRequest object, is that what you are sending it? It looks like you're using two different request objects in your code:
one when you get the dispatcher:
RequestDispatcher dispatcher = request.getRequestDispatcher
And then another when you forward the request to the jsp.
("/PersonalData.jsp");dispatcher.forward(req, res);
Make sure the req variable is referencing an HttpRequest object. The same goes for the response object you are passing it.
hope that helps
[ April 04, 2002: Message edited by: Dave Vick ]

Dave
Med Shabe
Ranch Hand

Joined: May 08, 2001
Posts: 84
Sorry for misleading you Dave,
There's a typo there. The request object is the same. So the problem still stands.
RequestDispatcher dispatcher = request.getRequestDispatcher ("/PersonalData.jsp");dispatcher.forward(request, response);
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Med
Can you post some more of your code and the exact error message and stacktrace your getting. That'll hel in figuring out what the problem might be.
Med Shabe
Ranch Hand

Joined: May 08, 2001
Posts: 84
Thanks for looking into this Dave. Below I have provided code anippet along with debug info.
I'm just checking for the value of radio buttons:

And it chocks on the rd.forward line.
Debugging info:
javax.servlet.ServletException: non-HTTP request or response
Method: POST
Path info: null
javax.servlet.ServletException: non-HTTP request or response
getMesage: non-HTTP request or response
Root Cause: java.lang.ClassCastException
------------------
Hope this gives you some clues.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Med
The only method in the code you posted that can generate a ServletException is the forward method. forward method only generates one if the resourse it is forwarding to throws one so the actual Exception is coming from the JSP your forwarding to.
From what the error message says I would double check to make sure the request and response objects you're forwarding are HttpRequest and HttpResponse objects. Is the servlet an HttpServlet? And are the req and resp varialbe the same ones you are passed in the doPost method?
If all of that is ok then post the entire doPost method and that should help.
Also, and don't take offense, did you modify the _jspService method in any way?
Med Shabe
Ranch Hand

Joined: May 08, 2001
Posts: 84
I have not modified the _jspService no.
based on your previous comment I think I know what I'm doing wrong now, but not sure how to get around it. I'm starting out with html and then try to go to a jsp page from the servlet. I've attached the doPost as you suggested. Perhaps I need to start up with a jsp instead. In that case do I need to pass the erquest, response objects to the servlet in order to utilize the forward action? If so, how? Thanks.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

One thing to note, from the API on RequestDispatcher.forward():

This method allows one servlet to do preliminary processing of a request and another resource to generate the response

I've always taken this to mean "do not start responding in the forwarder, leave it *all* to the forwardee.

Your line:
res.setHeader("Cache-Control","no-cache");

Kinda breaks that rule, and might be interfering with the forwarding.
 
Don't get me started about those stupid light bulbs.
 
subject: non-HTTP request or response Exception
 
Similar Threads
RequestDispatcher not throwing IllegalStateException
respnsce.setContentType()
RequestDispatcher doubts
RequestDispatcher doubt :(
RequestDispatcher