• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Calling a servlet from Java Class and receiving data from servlet

 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I apologize if its not in the right forum. I am trying to call a servlet from java class and get data from the servlet to the java class. I am having some issues(java.io.StreamCorruptedException: invalid stream header) with it.

My Java class




My Servlet class is







The exception I get is



The error line is ObjectInputStream in = new ObjectInputStream(aConnection.getInputStream());

I also wanted to know if I am able to access my servlet as I did, since the servlet print statements are not getting executed. I tried the same servlet URL in the browser, atleast I get the user values printed in the log file, but XML error in the browser display.

What am I missing here? Thanks for the help.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Considering the line numbers in your exception don't correspond to the line numbers in your source, I see Red Herrings.
One problem in the code you did post is that you never set the value of the object you are writing in the servlet response.
This isn't a problem you've had yet, but it could turn into one: since a servlet can be executed by several threads at the same time, it is a Bad Idea to use instance variables.
 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joe,

Thanks for the reply. The code I posted is modified as I had to remove some unwanted code and comments which were not relevant, hence the line number change. I did not mean to mislead, thats why I mentioned the statement.

Also, the servlet output "user_id" is set in the code before which I did not post, but did post a comment in line 48. I will also change the instance variables.

Am I calling the servlet correctly, as I am able to access it via the same url, but I am not seeing my print statements from the servlet(My first statement in the doPost method is a print).

Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic