File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

non-HTTP request or response Exception

 
Med Shabe
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Med Shabe
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic