Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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
Pie
Posts: 9264
10
Linux Mac OS X 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic