Invoke Local System service through Web Client

L

Lalit

Hi All,
I have a requirement in my J2EE web application that the web client
must be able to invoke local system service. Actually i want my web
client to be able to print on a printer connected locally. I know the
rule of web application is that it can not perform Files I/O with the
local system because of the serious security issues.
Can you suggest any way using applet or java web start or other than
these. The motive is to write on file "lpt1".
 
O

Oliver Wong

Lalit said:
Hi All,
I have a requirement in my J2EE web application that the web client
must be able to invoke local system service. Actually i want my web
client to be able to print on a printer connected locally. I know the
rule of web application is that it can not perform Files I/O with the
local system because of the serious security issues.
Can you suggest any way using applet or java web start or other than
these. The motive is to write on file "lpt1".

You could try using Java's printing API, though they are hard to work
with (IMHO), and you might still face security restrictions.

The other solution is to sign your web client, so that users may grant
permission to local resources (including file IO).

If you need more details, please specify whether your web client is an
HTML embedded applet, a Java Web Start Applet, a Java Web Start Application,
or something else.

- Oliver
 
L

Lalit

Hi Oliver,
Thanks for the reply.
If you need more details, please specify whether your web client is an
HTML embedded applet, a Java Web Start Applet, a Java Web Start Application,
or something else.

My application currently using JSP and JS only. I can use applets or
any Java Web Start application if necessery (However i m not willing
to), as i heard that web pages are not allowed to use local properties.
But that requirement is only to solve the purpose of printing data
locally from my web page.
Is it possible to add only one button of the applet on my JSP page?
 
A

Andrew Thompson

Lalit said:
(Oliver)

My application currently using JSP and JS only. I can use applets or
any Java Web Start application if necessery (However i m not willing
to), as i heard that web pages are not allowed to use local properties.

An applet in a web page, as well as a JWS application or
applet can do everything a normal application can do. So
long as..
- The code is signed.
- The user accepts the signed code (when asked by Java)

(Note that while an unsigned JWS application or applet *can*
print using the javax.jnlp.PrintService, it still requires the
end user's confirmation/permission - there are no 'free lunches'
when it comes to printing from a web-page - it requires the end
user's active involvement)
But that requirement is only to solve the purpose of printing data
locally from my web page.

The thing is, that is a big 'only'. If it were easy for a
'plain old web-page' to dump 300 page prints to a user's
printer without their active consent, that would be a huge
problem.
Is it possible to add only one button of the applet on my JSP page?

Probably not in the way you are thinking of.

You might have an applet in a page that automatically
tries to send a print (it does not need any buttons),
but the code would have to be signed, and the user
would be asked if they want to let this applet have
'unrestricted access' (or words similar) to the user's PC.

Why not offer the document itself to the web-surfer?
Let them decide whether they want to print it.

Andrew T.
 
L

Lalit

Why not offer the document itself to the web-surfer?
Let them decide whether they want to print it.

Actually my application is Enetrprise i.e. J2EE and user may have to
print in bulk. User needs to print Barcodes on a Barcode Printer and
that can be 10 or 20 in one go. So can not bug the user 20 times.
However involvement for allowing the applet by user is no problem.

Can such a solution like........"On clicking a button on JSP, an applet
launches which takes data from JSP e.g. 20 Barcode numbers and prints
on the printer.." will work? If yes, can you tell me the implementation
of such an approach.
 
T

Thomas Hawtin

Andrew said:
An applet in a web page, as well as a JWS application or
applet can do everything a normal application can do. So
long as..
- The code is signed.
- The user accepts the signed code (when asked by Java)

(Note that while an unsigned JWS application or applet *can*
print using the javax.jnlp.PrintService, it still requires the
end user's confirmation/permission - there are no 'free lunches'
when it comes to printing from a web-page - it requires the end
user's active involvement)

The Java Plug-in does allow printing, but throws up a confirmation
dialog first.

It surprised me when I first saw it. Or at least when I saw the deadlock
from trying to print off the Event Dispatch Thread (might not be a
problem any more).


But, I've seen many web pages with JavaScript "Print" links that
actually do bring up a print dialog. (Most annoying, because what I
really want is for the page to be formatted on the screen reasonably.)

Tom Hawtin
 
A

Andrew Thompson

Thomas said:
The Java Plug-in does allow printing, but throws up a confirmation
dialog first.

You do mean an unsigned applet in a web-page, right?
It surprised me when I first saw it.

It is news to me, as well. I would have expected a
SecurityAccessException (or similar), with no prompt.

Andrew T.
 
A

Andrew Thompson

Lalit said:
Actually my application is Enetrprise i.e. J2EE and user may have to
print in bulk. User needs to print Barcodes on a Barcode Printer and
that can be 10 or 20 in one go. So can not bug the user 20 times.
However involvement for allowing the applet by user is no problem.

Can such a solution like........"On clicking a button on JSP, an applet
launches which takes data from JSP e.g. 20 Barcode numbers and prints
on the printer.." will work?

Yes. Well, sort of..

After the applet is loaded (and assuming it is only ever
called when the user wants to print) it might automatically
initiate a print - but the user is asked to confirm it is OK.

So that is 'two clicks' from the time the user wants
to print the data, to when they see a print dialog.
For a print to take a 'couple of clicks' would be no
surprise to most users - so I don't see it as a
problem if the want the print.

But do the barcodes need any special formatting?
(Is it possible to present them on the web-page in such
a way that the user can simply print the web-page itself?)
Sorry - I am not that familiar with printing barcodes.

Assuming the barcodes *do* require special formatting,
then - yes, the applet can theoretically print them in one
go - send them all in the same print-job - after the end-user
has OK'd the print-job just once.

(BTW - are these barcodes in the JSP as text, or
images, or something else?)
..If yes, can you tell me the implementation
of such an approach.

No. I have never dealt with the print API, and am not
very familiar with bar-codes.

I sugggest you split this into two separate problems
1) Printing the barcodes.
2) Printing from an applet.

Note that you might experiment with printing (some generic
and simple document) from an applet, just to check the
way the security model works - assure yourself that the user
can 'OK' a print of one - or many - pages with a single click.

OTOH I would advise doing most of your work with the
printing API from an *application*. You might write your
class so it works as both.

Applications are much quicker and easier to develop and
debug, especially when the project requires access to
priviledged resources like the printer.

I hope that makes it a bit more clear (and that I have
not misunderstood what Thomas mentioned - that
was a surprise to me).

Andrew T.
 
L

Lalit

Hi Andrew,
I sugggest you split this into two separate problems
1) Printing the barcodes.
2) Printing from an applet.

Printing thr Barcodes is not a problem. I can easily do it using a java
class i have already written. My main problem is Problem 2. I m
completely new to Applet world. I do not know how to write an applet
which can be invoked through JSP page and how to edit the prompt
message it will ask from the user while taking permissions to load.

Mainly experimentation with the following approach that you have
mentioned.
Note that you might experiment with printing (some generic
and simple document) from an applet, just to check the
way the security model works - assure yourself that the user
can 'OK' a print of one - or many - pages with a single click.

However, thanks a lot for the reply.
 
A

Andrew Thompson

Lalit said:
Hi Andrew,


Printing thr Barcodes is not a problem. I can easily do it using a java
class i have already written. My main problem is Problem 2. I m
completely new to Applet world. I do not know how to write an applet
which can be invoked through JSP page and how to edit the prompt
message it will ask from the user while taking permissions to load.

You can't. If you could, the message
"Would you like me to upload your bank account
details then wipe your system?"

...might be 'helpfully' edited by some nasty person, to..
"Want some chocolate?"

Andrew T.
 
L

Lalit

You can't. If you could, the message
"Would you like me to upload your bank account
details then wipe your system?"

..might be 'helpfully' edited by some nasty person, to..
"Want some chocolate?"

Ha ha ha..good one. Got your point that the message can not be changed.
I think i should do some hands on on the applet first.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top