JSP generates Word documents, Excel documents, PDF documents

Source: Internet
Author: User

in Web-oa system, document management seems to be indispensable, sometimes need to query some data from the database in some format output, and in the form of Word documents, and sometimes many word documents saved to the database in the Blob field of a table, The server then presents the picture file saved in the Blob field to the user. Search through the internet found little about this kind of article, now sorted up for your reference.














1 generates Word documents directly on the client side








A Word document on a JSP page is very simple, simply change the contenttype= "text/html" to Contenttype= "Application/msword charset=gb2312" and the code below :














<%@ page contenttype= "Application/msword charset=gb2312"%>











lets you make the contents of the original page appear in Word by setting.














If you need to download a Word document, simply add the following code to the JSP page:











<%











response.setheader ("Content-disposition", "Attachment;filename=filename.doc");











%>














where filename in Filename.doc is the file name of the Word document to download, it can be customized by <%=docName%> from line, as follows











<%











response.setheader ("Content-disposition", "Attachment;filename=<%=docname%>.doc");











%>











This provides a hint for the user to choose from the image shown below














Tips: If a programmer needs to build a Word document in a format that he or she has designed beforehand in Word, you can copy the word format and paste it into FrontPage, with the HTML code pasted into the JSP page.





 





2 The Word entity in the database exists in the client output








Here we only discuss Word document entities in a BLOB field in client output Oracle. The class Getblobbean is invoked, which provides the ability to remove the blob from Oracle, with the following code:











package yourpackage;

















import javax.servlet.*;











import javax.servlet.http.*;











import java.io.*;











import java.util.*;











import oracle.sql.*;











import beans.yourbeanpackage. Getblobbean;

















/**











* <p>title: </p>











* <p>description: </p>











* <p>copyright:copyright (c) 2004</p>











* <p>company: </p>











* @author not attributable











* @version 1.0











 */

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.