简体   繁体   English

在java web应用程序中如何从客户端打印服务器文件

[英]In java web application how to print server file from client side

In the java web application need to select the file from server and print to the local printer. 在java Web应用程序中需要从服务器中选择文件并打印到本地打印机。 how it can be done 怎么做

Thanks in advance 提前致谢

You will need an applet , flash , silverlight , javafx - ie an embedded app. 你需要一个appletflashsilverlightjavafx即一个嵌入式应用程序。 There: 那里:

  • download the file from the server by creating a GET request (in an applet - using URL.openConnection() ), obtaining the returned bytes and forming an in-memory document 通过创建GET请求(在applet中 - 使用URL.openConnection() )从服务器下载文件,获取返回的字节并形成内存中的文档
  • sending that to a printer. 将其发送到打印机。 If you chose applet - this might help 如果您选择applet - 这可能有所帮助

(I'm not aware whether the same flow can't be achieved with javascript as well) (我不知道javascript是否也无法实现相同的流程)

That's going to be tricky whenever you require a minimum of user interaction (ie just click the link and then do the print magic) and it also depends on the type of the file in question. 每当您需要最少的用户交互时(即只需单击链接然后执行打印魔术),这将是棘手的,它还取决于相关文件的类型。 If it is for example a .doc file, then you would basically need to download it to the client environment and open it in the default associated application (MS Word in this case) and then let the application execute the print command. 如果它是例如.doc文件,那么您基本上需要将其下载到客户端环境并在默认的关联应用程序(在本例中为MS Word)中打开它,然后让应用程序执行print命令。 You can't do this from the server side on. 您无法从服务器端执行此操作。

Your best bet is to create an Applet which in turn displays the file tree, downloads the file to the local disk file system on client interaction and makes use of Desktop#print() to print it. 最好的办法是创建一个Applet ,然后再显示文件树,在客户端交互时将文件下载到本地磁盘文件系统,并使用Desktop#print()打印它。 Eg 例如

File file = new File("/temp/file.doc");
// Read file from server using URLConnection, write it to this file and then do:
Desktop.print(file);

But if it are for example plain text files such as text/html , text/xml , etcetera, then you can make use Javascript to load the file into some <div> or <iframe> element and then execute the window.print() method on it, if necessary along with a CSS media rule . 但是如果它是纯text文件,例如text/htmltext/xml等,那么你可以使用Javascript将文件加载到某些<div><iframe>元素中,然后执行window.print()方法,如果有必要,还有CSS媒体规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从服务器端脚本中打印出Java Web应用程序 - print out of java web application from server side script 文件未在客户端Java(服务器/客户端)App No Web中启动 - File not launching in Client Side Java (Server/Client) App no Web 如何处理从Java客户端上传服务器端HTTP文件 - How to handle Server side HTTP file upload from Java client 用Java编写的Web应用程序如何在客户端打开文件? - How can my web application written in Java open a file on the client side? Java客户端/服务器应用程序-如何从服务器端获取输入类型? - Java client/server application - how to get the input type from the server side? 如何在服务器端而非客户端的JAVA中逐行从config.properties文件读取数据 - How to read data from config.properties file line by line in JAVA on the server side not on the client side 如何在客户端/服务器Java应用程序中传输文件 - How to transfer a file in a client/server Java application 如何-Flex客户端和Java作为服务器端 - How to - Flex client side and Java as Server side 从服务器端触发网页打印 - Triggering a web page print from server side 使用Java套接字将文件从服务器传输到客户端。 服务器端错误,文件传输到客户端为空 - File Transfer from Server to Client using java sockets. Error on Server side and File transferred to client is empty
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM