Printing in Java...
I wrote an applet to locate a printer and print the document.
The document which i sent to the printer is the one which i created programatically using the Book Class and Pageable.
Now what i want is, whether the applet should be able to stream data from the server and print that to the printer.
My server is not java servlets.
Its in .NET; ASP.NET and C#
Can this be possible?.
Example code will be appreciated.
Thank You for ur help.
> My server is not java servlets.> Its in .NET; ASP.NET and C#Why should that matter? Connect and get the data. How the data is obtained is irrelevant.> Can this be possible?.Sure. UrlConnection and you're done.
I will repeat my post [url= http://forum.java.sun.com/thread.jspa?threadID=760602]here[/url] about the networking tutorial if you like?
mlka at 2007-7-14 20:39:03 >

yes i'm able to establish a URLConnection to the server but what i'm getting is hmtl contents not the data which the outputstream had sent
> yes i'm able to establish a URLConnection to the
> server but what i'm getting is hmtl contents not the
> data which the outputstream had sent
Then you're obviously connecting to the wrong thing. Or it's the correct thing and it delivers something else than you assumed it would.
This is my applet code for URL Connection.
URL currentPage=getCodeBase();
String protocol = currentPage.getProtocol();
String host=currentPage.getHost();
int port=currentPage.getPort();
String urlSuffix="/PrintAppletCSharp/Default.aspx";
System.out.println("currentPage : " + currentPage + "\nprotocol : " + protocol + "\nhost : " + host + "\nport : " + port);
try {
URL dataUrl=new URL(protocol,host,port);
URLConnection connection=dataUrl.openConnection();
connection.setUseCaches(false);
connection.setRequestProperty("header", "value");
System.out.println("Got a connection");
BufferedReader in=new BufferedReader(new InputStreamReader(connection.getInputStream()));
System.out.println("After Getting a connection");
String line="";
while(line!=null)
{
line=in.readLine();
if(line!=null)
fromServer+=line + "\n";
System.out.println("Line " + line);
}
repaint();
} catch (Exception ex) {
ex.printStackTrace();
}
http://forum.java.sun.com/help.jspa?sec=formatting
URL currentPage=getCodeBase();
String protocol = currentPage.getProtocol();
String host=currentPage.getHost();
int port=currentPage.getPort();
String urlSuffix="/PrintAppletCSharp/Default.aspx";
System.out.println("currentPage : " + currentPage + "\nprotocol : " + protocol + "\nhost : " + host + "\nport : " + port);
try {
URL dataUrl=new URL(protocol,host,port);
URLConnection connection=dataUrl.openConnection();
connection.setUseCaches(false);
connection.setRequestProperty("header", "value");
System.out.println("Got a connection");
BufferedReader in=new BufferedReader(new InputStreamReader(connection.getInputStream()));
System.out.println("After Getting a connection");
String line="";
while(line!=null)
{
line=in.readLine();
if(line!=null)
fromServer+=line + "\n";
System.out.println("Line " + line);
}
repaint();
} catch (Exception ex) {
ex.printStackTrace();
}
And now see Reply 4.Also, if you're expecting data: why do you use a Reader?
then what else? other than a reader?think u know the answer then please explain it more clearly.
> then what else? other than a reader?
>
> think u know the answer then please explain it more
> clearly.
I probably know the answer, but I don't know the question. You said you expect "data". All I know is that "data" is "not HTML". Assuming that it's also not other text, a Reader is the wrong tool. The correct one I don't know because I can't read your mind.
ok then let me make it more clear.
i want the server to send a data "Programmer" for example to the applet
When i opened a connection as in the source code..what i got was the complete HTML of that page containing the applet.
But i want the data "Programmer" to be read by client
The server is C# in .NET.