Jasper report printing on client side - java

On WebSphere portal I am trying to use JasperReport print functionality.
JasperPrintManager.printReport(jasperPrint, true);
This way works fine for WAS and localhost.
But when I deploy the application on Remote server, the dialog of print is not appearing and no printing work is done.
Although I have used JavaPrint service to lookup all the printers and then select one for printing the task but it is not even working that way.

Your solution works on localhost because your client and server are the same machine. Thus calling a print command on the server side will make it look like it's printing from the client.
But you don't want it to print on server. You want the client's browser to have access to the report in a printable format. A common format is PDF.
As #AlexK mentions in the comments, there are already multiple other questions (with answers) on how to do this.
My suggestion for getting this done in a portlet is to have a button in your portlet view that will make a call to a serveResourceURL and download a PDF version of the report. The serveResource method was designed for situations like this where developers need to serve content other than HTML.

Related

Installable Java program talking to the browser

I have a native (installable) Java program that constantly generates certain data (only numbers and text). I want to send that data to the browser. I am looking for something similar to node.js with socket.io
I want to send data (text and numbers only) from java stand alone application running on the client's PC to the client's browser and display this data as a standard website (HTML CSS and JS).
Take a look at this image. How would you approach this problem?
Take a look at this image as well.
So
1 - Everything work on the PC
2 - principal concept: if you choose to use a browser, the control comes from the user + browser (which can choose to retrieve data, push buttons, etc.). Nothing outside can decide to send data to a browser if it didnt ask it. Function of a browser is to browse.
one solution:
you production app build the data and put it in some file, it can format it in HTML : format option 1 (or raw data : format option 2)
the data produces can be put on a local file (store option 1), or to be used by a web server (store option 2), even with the same file.
store option 1: just use your brower to browse your directories:
something like that: file:///C:/truc.html
store option 2: you need a local web server:
instal some (heavy for each PC): tomcat, or glassfish
it can deliver static page for format option 1 (same result as store option 1)
or it can proces with a java/jsp program which retrieve raw data and show it as html (format option 2)
You dont need sockets, or network functions.
In your schema: the background process:
can work with the webserver (or event read or change some datas in the database).
dont have to talk with the browser. The browser needs only to talk with the server, which works with your background process.
your background process can be hosted in the server. It can be scheduled by quartz on glassfish (tomcat, or other web servers). In this design, you finally only need a browser and a client.

How to lauch java program on server from web page

I have a simple java program that take some parameters to create an image. I want to set up a website in which the user can choose the parameters and, from his ok pressed, the server runs the program. When the program has finished, an image is on the server so the web user can see the result. How can I do that? Which technology I need? Something like JSP or only java installed on the server? Normally, hosting services have this possibility by default or I have to choose some advanced options? Just to have an idea... Thanks!
You can do it with java, but also with php if you need it (php is generally more available and in my opinion quicker to setup).
You have your form send data as GET / POST request;
at the other end you have a web/application server receive the data (some kind of REST service or just a plain script), execute your image generating routine/program and then take this image and return it through http.

Java creating server that is ran as one file with database?

I have a program that I've created that is meant to poll an html internal page with different IPs that update and then will run a telnet session to those IPs to see if the device still has a connection... I'm attempting to challenge myself in creating something further with a dynamic webpage instead of my program spitting out console output...
My Issue:
I dont know what technologies / libraries Java has to execute such things
I want:
A Local Server, to upload a page LOCALLY only (no security is needed as this will be strictly intranet)
My program to implement: A database of sorts to save "logs" essentially that a certain IP / device has had successful connections
in the past....maybe stored to an external file is fine i presume (my
program currently has to re-poll everytime i run it.. i want some kind
of "remembering"..
Is it possible this can all be done in one file? so if i want my computer to run this as soon as it starts up... it will run... grab
its current state of the database of IPs... poll them (periodically)
and then persist and save and update the HTML page dynamically....
I hope i'm being as descriptive as possible... Its a bit of an abstract.. I really just want some introduction to different libraries ... a friend recommended stuff like MongoDB or something but I want to stay strictly to Java programming

Make PHP execute and communicate with a Java application on a web server

I have a java application that will take the image as an input and output another image. I have a website with a popular host (PHP+MYSQL Hosting). I want to create a page on the website with PHP with a form where a user can upload an image which will then pass the image onto the Java application.
What I am planning on doing is when then user uploads the image, it gets stored in a folder on the web server. I will then call the java app on the server passing the url of the image as an argument and then the java app will output another image, let’s say, to a result folder. The PHP page after the execution will then display the result image on the browser.
Now my questions are:
Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?
The java app is fairly heavy as it does a lot of image processing. Should I offload the java app to another web server? If yes, are there any services that will run my java app?
(Optional) It’s a demo of my java app and I don’t want to store the images people upload. Is there a way where I can directly pass the uploaded image to the java app and output the image generated directly instead of storing it on the web server? I would prefer this because, if the image is big, I can make PHP stop the execution after a timeout.
How do I communicate with the java app from PHP for info on its execution, for example When PHP calls the java app, the page has to wait till the app finishes processing? I want the java app to send a response to the PHP page saying that the processing is completed and the page is redirected or refreshed accordingly.
I hope you get the idea, please suggest the technologies that I can use to implement this and also if you have a better idea, post it!
Thanks!
Now my questions are: Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?
It's technically possible. But the hosting has to install JRE at the host and give the PHP user sufficient OS-level and filesystem-level permissions. So you're really dependent on the hosting whether they provide this opportunity. Best is to just contact their support team and ask it.
If it is supported, you could just use shell_exec().
$result = shell_exec("java -jar /path/to/imageprocessor.jar " + $imagepath);
if ($result) {
// Shell execution succeed.
} else {
// Shell execution failed.
}
For asynchronous communication / background processing, the client has to fire an ajaxical request.
If it is not supported, consider porting Java to PHP. The GD image library has pretty a lot of functions which may be of use.
Google App Engine allows to host Java (and Python) web applications. The SDK and the basic account is free of charges. With the SDK, you could develop and test the application locally and then simply deploy to App Engine (NetBeans and Eclipse plugins are available).
Then the PHP app could send the data in a HTTP POST to the Google App Engine application and get the result in the response data.
Or the data is stored first in a database blob and a processing job is put in a task queue (a 'message queue'). This has the advantage that the PHP client request will return immediately after the data has been POSTed. Then, the PHP application could poll for the result data while Google App Engine processes the image. The PHP side would be more responsive this way.
Wouldn't it be easier to make your java app a web app, that PHP could call via an url in wich he would put the url of the image so java can download it?
like http://yourjavaserver/imageprocessing?imgurl=IMAGE_URL
and the java servlet would reply with the image file itlsef.
You can look for "java hosting" on google, to find a host for this, but it's more expensive than PHP hosting. Maybe the best choice would be to get a dedicated server which could host both PHP and java applications...
I think your best bet here is with your java app running as cron(or a deamon) that can load the file details from the database. This will require a (one or more) page-refresh on the users part after the generation is complete, at which point your script can recall the image from the database/filesystem.
I do not think you will be able to do this in real-time due to timeout restrictions on the PHP webpage. However, you could write a java applet that can take the file and process it before sending it to the server (or depending on how you intend to use it, perhaps you do not need to upload it after the transformation?).

Print service on java web application

I have an Enterprise Java web application that all of the business is migrated from client-server application. So I need to adapt all requirement including printing on every client (Using Dot Matrix / Plain text).
Printing requirement for client on separated client is they must get the report right away after the process is finished, let say print some system information. On Client-server is easy just for printing, but when I migrate to web apps, we used Server/applet service that embedded to the apps. So the applet will be initialized when the client open the browser.
It works, but too many issues. Sometime the applet is closed suddenly without action from client, so automatically the applet will be failed for checking the queued report from database. Is there any suggestion for this case?
I use Spring Framework as a business layer.
I had the same problem years ago.
This is what I did.
Since my processing was taking place on the server, I knew when the transaction was finished. So what I did was to send the print request directly from the server. The client printer was configured in the server and since it was used in the LAN it could be easily reached. That way I finished with all the problems I had with the applet, the tradeoff was they can only print in the office, but in my situation that was fine, not necessarily applies for you, give it a try.
UPDATE
In my case, the print was needed by different departments along the country.
Each department had an specific, unique printer for that task. So what I did was have that printer mounted in the server filesystem ( in Unix something like /Volumes/printers/EPSON-12345 , in Windows as x:\printers\EPSON-12345 ) When the user finished the transaction in the webapp I start in the server a print request. Java does not have any problem at all to print to a local printer and since a mapped printer is taken as local ( even though it is a remote one ) you don't need further authorizations or anything special.
Since I knew what the specific printers were mapped, and I knew what kind of transaction that was, I knew where to print.
Finally I use a property file to allow the printer to change from time to time and/or add more printers.
I don't quite remember the details but it was something like this in the server:
ResourceBundle bundle = ResourceBundle.getBundle("printers");
String serviceName = bundle.getString("MEXICO.CITY.PRINTER");
PrintService service = PrintService.find( serviceName );
service.print( // document and etc );
But that was almost 4 yrs. ago so I don't remember exactly the details, but my program is still running :)
You can read more about the printing service in java here. It is way much simpler than what it look like.
Other ways to achieve a good result:
generate a PDF (using iText, or better JasperReports) on the server, and send it for download to the client, where he can print it.
have a print.css, and generate a web-page that is suitable for printing.
If you do not want the client browser to orchestrate the printing (i.e. by sending a binary blob with a custom MIME-type which the user must set up to be sent to the printer), you must let your server do it.
This usually means that the user must have a default printer attached to their profile, and that the server knows how to send prints to that printer. Lots of fun :)

Categories