aspose file tools*
The moose likes Servlets and the fly likes Communication with Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Communication with Servlets" Watch "Communication with Servlets" New topic
Author

Communication with Servlets

Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Hi all,
This is my Clint

This is my servlet


This is the error I am getting

run-single:
done 1
java.io.StreamCorruptedException: invalid stream header


My problem is how my application can get the data taken from MYSQL database by the servlet
I want to view this data in my application
This application(Not the servlet. The one on the Clint side)is not an applet(web based). It is a class that extends JFrame(The one with the getdeleteText() method).

Thanks you
[ October 28, 2005: Message edited by: Sameera Abeysinghe ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Your servlet class extends what?
Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Hi,
I have edited the original post
Thank you
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42584
    
  65
Are you sure that it is possible to connect to a URL that contains GET parameters in this fashion?


Ping & DNS - my free Android networking tools app
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
I believe calling connect.setDoOutput(true); makes request post and servlet expects post data. Remove it or do false.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Hi,
Thanks for the fast reply�s

Are you sure that it is possible to connect to a URL that contains GET parameters in this fashion?


I believe calling connect.setDoOutput(true); makes request post and servlet expects post data. Remove it or do false.


I am very new to servlet programming so a working code will be a big help

This is what I want to do

I send the groupid(variable group) to the servlet through the url. It works fine.
The servlet takes that groupid and get some data from the database. That also works fine.
My problem is after getting the data what I have is a result set. I want the data in this result set to be shown in my application.
How can I do it
(I think the servlet has to send it so �.)
Thanks
Amarender Reddy
Ranch Hand

Joined: May 12, 2005
Posts: 54
Hi,

If your application has a JSP front-end with more number of fields and othe rdata vallidations to be done then you should be using taglibs ( the very famous ResultSetIterationTag ) ..........or if your application has only few fields to be populated then directly put them in a session and access them at front-end.

hope u understood

regards,
amar

****************************************************************************


BE GOOD AND DO GOOD. THAT IS THE WHOL EOF RELIGION.
-- Swami Vivekananda
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42584
    
  65
I don't see what JSP has to do with any of this.

One basic problem you have is that you call both response.getOutputStream and response.getWriter. That won't work, you can only use one of them at a time. (I'm actually surprised you're not getting exceptions when you do that, but that's a different topic.)
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Sameera Abeysinghe:
My problem is after getting the data what I have is a result set. I want the data in this result set to be shown in my application.
How can I do it
(I think the servlet has to send it so �.)


Yes you need to respond back after processing. Technically, you need to take a request dispatcher from your request object and then do forward. It would be forwarded to the view/JSP. Otherwise you can render the response in your servlet as well.

Tip: While forwarding request to some JSP page in order to show the result. Bind your collection of TO to request object. Where collection of TOs would be filled by your resultSet.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
As you are a newbie, I must tell you about TO.
Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Ones again Thank You for the reply�s
But I am not sure you all understood my problem.

amarender reddy -- your application has a JSP front-end with more ....

My application is not web based(so no jsp or applets)
Sameera Abeysinghe -- side)is not an applet(web based). It is a class ....

Ulf Dittmer -- actually surprised you're not getting exceptions ...
I was testing to find a way to do this so don�t know what exactly I did

Adeel Ansari -- Tip: While forwarding request to some JSP page in order to show the result...........
My application is not web based(so no jsp or applets)
Sameera Abeysinghe -- side)is not an applet(web based). It is a class ....

The link TO is useful. But not sure it can do what I want
So more reply�s is always well come.

Thanks a Lot for all your fast reply�s
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12821
    
    5
Why are you trying to read the response as an ObjectInputStream?
It is very clearly going to be a text stream since you did a response.getWriter(0)
Of course it is corrupted.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Communication with Servlets