• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

non-HTTP request or response Exception

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic