aspose file tools*
The moose likes I/O and Streams and the fly likes Calling a servlet from Java Class and receiving data from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Calling a servlet from Java Class and receiving data from servlet" Watch "Calling a servlet from Java Class and receiving data from servlet" New topic
Author

Calling a servlet from Java Class and receiving data from servlet

vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279

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

Joined: Oct 29, 2001
Posts: 8713
    
    6

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling a servlet from Java Class and receiving data from servlet
 
Similar Threads
how to send parameters form applet to servlet
Signed applet talking to server other than its own
receiving serialized object from servlet to applet
Exception invalid stream header: 74000346
calling servlet from java program and more