Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Calling a servlet from Java Class and receiving data from servlet

 
vjy chin
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • 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.
 
Joe Ess
Bartender
Posts: 9612
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic