This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes output as URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "output as URL" Watch "output as URL" New topic
Author

output as URL

jeff ukridge
Greenhorn

Joined: Nov 21, 2005
Posts: 16
Hi,

I have an applet that connectes to my server. At one point during the execution of the applet I load another web page into the browser using the following code:



This works pretty well. I would like to replace the "test.html" above with the output of my server instead.

Right now I have a variable called "out" that is the output stream of my socket connection to my server.



Instead of referencing test.html, is there any way I can read the contents of "out" instead?

Something like this:



That code doesn't work. I put it here just to help give you an idea of what I'm looking for. Can I read the output of my server and use it as input to a URL constructor?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Notice that you are using an OutputStreamWriter. Does it make sense to read from an output socket? I think you need an InputStream or a Reader (perhaps even an InputStreamReader) to do what you want. I have a feeling that you need to learn more about the fundamentals of I/O in Java. You should work through the I/O Trail from Sun's Java tutorial (see the link in my signature for the full tutorial) in order to get a better grasp on I/O basics. Once you understand the basic functionality of the I/O API, you will find the Java API documentation (again, see the link in my signature) to look up specific classes and methods.

I hope this helps.

Layne
[ February 14, 2006: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
jeff ukridge
Greenhorn

Joined: Nov 21, 2005
Posts: 16
No. I've got the I/O down. I should have proof-read my message before positing it. Clearly I am not trying to read from an output stream writer in my application.

I simply rushed the post and copied the wrong section of code.

My questions remains though.

Can I read output of my server (which would be text composed entirely of HTML code) and use it as input to a URL constructor?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
No, because HTML and a URL are just different things. You can read all the HTML into a string, pass the String from the applet to JavaScript on the page, and set the inner HTML of some widget which should make it appear pretty quickly. Passing from applet to script and setting the HTML element are both things I've done like once in my life. I know it can be done, but can't give you the syntax.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41083
    
  43
Just in case you want to go down that route: Stan is talking about a technology called LiveConnect, and you can find information about it in the Applets FAQ.


Ping & DNS - my free Android networking tools app
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: output as URL
 
Similar Threads
Request web Page on Glassfish server using java code
Could not able to open the file in the local system using http protocol
What's wrong here!
pass a file from a server to another using servlets or ?!.
Client Applet- server application