In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to realize the function of previewing documents online in Java? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Public void view (HttpServletRequest request, HttpServletResponse response) throws IOException {try {/ / your document address String file = "http://view.xdocin.com/doc/preview.docx"; / / XDOC document preview service address String xurl =" http://view.xdocin.com/xdoc"; / / preview parameter Map params = new HashMap () / / get preview result url params.put ("_ func", "url"); / / result format XML params.put ("_ rformat", "xml"); / / document address params.put ("_ xdoc", file); / / whether word document is displayed in pdf mode. Default false / / params.put ("_ pdf", true) / / watermark text, showing watermark / / params.put ("_ watermark", "XDOC document Preview"); / / whether to allow saving PDF. Default true / / params.put ("_ saveable", false); / / whether to allow printing PDF, default true / / params.put ("_ printable", false) / / whether to select copied content, default true / / params.put ("_ copyable", false); / / whether to display the bottom sidebar, default true / / params.put ("_ toolbar", false); / / Custom title / / params.put ("_ title", "document Preview") / / Preview link validity period (in minutes) / / params.put ("_ expire", 30) by default; / / call URL StringBuffer sb = new StringBuffer (); sb.append (xurl); Iterator it = params.keySet (). Iterator (); String key; boolean first = true While (it.hasNext ()) {key = it.next (); sb.append (first?':'&'); sb.append (java.net.URLEncoder.encode (key, "UTF-8")); sb.append ('=') Sb.append (java.net.URLEncoder.encode (params.get (key). ToString (), "UTF-8"); first = false;} / / get the preview result URL, jump to URL url = new URL (sb.toString ()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance (); factory.setValidating (false); DocumentBuilder builder = factory.newDocumentBuilder () Document document = builder.parse (url.openStream ()); document.getDocumentElement (). Normalize (); Element root = document.getDocumentElement (); if (root.getAttribute ("success"). Equals ("true") {/ / Preview result URL String viewUrl = root.getElementsByTagName ("result"). Item (0). GetTextContent () / / Jump response.sendRedirect (viewUrl);} else {throw new RuntimeException (root.getElementsByTagName ("error"). Item (0). GetTextContent ();}} catch (Exception e) {e.printStackTrace () }} this is the answer to the question about how to realize the online preview document function in Java. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.