Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I have a server and a client in a WEB JAVA APPS How can i make that the client prints to and not only the server?

Posted on 2008-06-16
8
Medium Priority
?
437 Views
Last Modified: 2013-11-23
I have a server with a printer and a client with its own printer, the cliente is calling the server by an IP like http://<<IP>>:<<port>>/<<instance>> i have a print function and it works perfectly in the server but when i call it from the client it doesnt print with the localhost printer of the client instead of that the server resolve it and print in the server printer.

I need a example code please i try it everythign.

notes:  
  Language JAVA
  The printing must by directly, if the printer dialog box ( like ctl-P in Microsoft word) appears it doesnt work for me.
  The content wich will be printed is a string not a file

regards

Mark
0
Comment
Question by:quicksystem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 21808255
If the IP resolves to the printer on the server then I'd say you need to look at your network configuration. This hasn't got to do with Java. What does the network admin say?
0
 

Author Comment

by:quicksystem
ID: 21810436
I think i didn't explain my proble clearly, so here we go again:

I have a server "myServer" with an application, then i have 2 clientes "client 1" and "client 2" like in the followin example:

MY SERVER
    MYSQL
    JDK
    TOMCAT
    MY WEB APPLICATION(ALL JAVAS AND JSP'S)
    IE6
    PRINTER

CLIENTE 1                      CLIENT 2
   IE6                                  IE6
   PRINTER                          PRINTER


Now if i want to run my application in the server i just use http://localhost:8080/myApplication/printTicket.jsp ( this jsp have only a request to a class who send the String data (not a file) to the printer) and the localhost (myServer) printer prints the string data ( for example hello word).

Then if I want to run this application in one of my clients i need to open a web browser and in the URL types http://myserver:8080/myApplication/printTicket.jsp when i press enter the client send the request to the server to solve it. When the server finished send to the client the response. (JUST HTML)

Now if i run this in the client, the printer that the request use is the server printer because the server resolves the request (and not the client). So the localhost (the client printer) didn't print any thing.

What i'm trying to do?
That the client send the request to the server and the server gets the client printer and print in it, not in the server printer.

One way to solve this proble is using the printer dialog to select the prefered printer ( like when we press ctrl-p in Microsoft Word) but this not solve my problem 100%. Cause the request i have is to print directly with no adicioanl dialogs boxes.

Regards

Mark






   

0
 
LVL 35

Expert Comment

by:girionis
ID: 21811053
What you could do then is to get the IP of the client that issued the request. You can use the getRemoteAddr()  method of the request object. You then check the IP. If the IP is the same as the server's IP then you print to the server printr, otherwise you print to the client printer. But the issue I see here is how the server could resolve the printer on the client.

Another thing is that you might be able to do it by using JavaScript, but I am nto sure about that.

WHy do you not want to have the printer popup box show up? This is exactly what it's used for.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:quicksystem
ID: 21813387
Girionis now we are getting close to the solution, the reason i don't what the printer popup box is because is a client request. ( So if the client pays they rules, and our job is create dreams thats why we all like to program jejeje).

I need to know how to set a remote address to select the printer. I show you the pice of code i use to make this task.

Perhaps ( and the must porbably) we need to change this lines. But i have been trying and this is the only way i found. Of Course you are an expert an maybe can help to fix it using an IP (request objetc), the hostname (request objetc) and the printer name (default name and in hardcode).

I found an example , but is a file print example and it doesnt work for me because i print a string( well i think not 100% fo sure)

//send the print job to a network printer.
    //were Au-4022 is the hostname and hp1100 the printer
     ...new FileOutputStream("//Au-4022/hp1100");


could you help me we a pice of code?


Regards

Mark
/*
    DETECTIN PRINTER
 
*/
 
// We create the Print job object   
   PrinterJob job = PrinterJob.getPrinterJob();
                  //We search all the posible printers
                    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
                  //If there are only 1 printer the rule says is the one, no matters what.        
                   if(services.length == 1){
                        job.setPrintService(services[0]);
                    }else{
                  //other wise we look for the QSPRINT prefix ( thats the one we need)
                        for (int l = 0; l < services.length; l++) {
                            if(services[l].getName().substring(0,7).equalsIgnoreCase("QSPRINT")){
                                job.setPrintService(services[l]);
                            }
                        }
                    }
 
/*
 FORMATING THE PRINT THE VARIABLE TICKET IS AN STRING
*/
                    // Hacemos imprimible el objeto ObjetoAImprimir
                    f = new PageFormat();
                    Paper p = new Paper();
                    p.setImageableArea(0, 0, p.getWidth(), p.getHeight());
 
                    p.setSize(0, 0);
                    f.setPaper(p);
 
 
                    job.setPrintable(new ObjetoAImprimir(), f);
                    //JUST MAKING THE FORMAT
                    lineas = StringVerify.tokenizerTicket(ticket,"\n");
                    page = 1;
                    column = 0;
                  //SEND TO THE PRINTER
                    job.print();

Open in new window

0
 
LVL 35

Expert Comment

by:girionis
ID: 21816423
>//send the print job to a network printer.
>    //were Au-4022 is the hostname and hp1100 the printer
>     ...new FileOutputStream("//Au-4022/hp1100");

This should work, since a file is just a resource on the network. You could print to a printer by using a PrintStream that is using a FileOutputStream.




FileOutputStream fos = new FileOutputStream("//Au-4022/hp1100");
PrintStream ps = new PrintStream(fos);
ps.print(<your object>);
ps.flush();
ps.close();

Open in new window

0
 
LVL 35

Accepted Solution

by:
girionis earned 1400 total points
ID: 21816550
The other thing you could do is to change your programme a bit, to print to the network printer. So when it finds the printer on the network you simply print there.

> I need to know how to set a remote address to select the printer. I show you the pice of code i use to make this task.

You shouldn't really need to do it. The PrintServiceLookup should return all the printers, even those who are on the network (assuming same network. If you want to use printers on a windows machien while you are using windows you should use samba).
for (int l = 0; l < services.length; l++) {
                   if(services[l].getName().substring(0,7).equalsIgnoreCase(<name of the printer on the network>)){
                                job.setPrintService(services[l]);
                            }
                        }

Open in new window

0
 

Author Comment

by:quicksystem
ID: 21819326
Thanks the solition was implemented.


Rgards

Mark
0
 
LVL 35

Expert Comment

by:girionis
ID: 21820177
Thanks for accepting, glad I was of help :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question