How to in Web

zhaozj2021-02-12  126

How to generate a Word file in the web_oa client

In a Web-OA system, the official document management is indispensable, and sometimes some data is queried from the database in some format, and the Word document is displayed in the form of a Word document, sometimes many Word documents saved to a table in the database. In the BLOB field, the server will present the image file saved in the blob field to the user. Finding online findings found that there are very few articles such as such classes, now they are now sorted up for your reference.

1 Generate a Word document directly in the Client

Generating a Word document on the JSP page is very simple, just change contenttype = "text / html" to contentType = "Application / Msword; charset = GB2312", the code is as follows:

<% @ Page ContentType = "Application / Msword; Charset = GB2312"%>

The content of the original page can be manifested in Word by setting.

If you need to download the Word document, just add the following code on the JSP page:

<%

Response.setHeader ("Content-Disposition", "Attachment; FileName = filename.doc");

%>

Where filename.doc is the file name of the Word document to be downloaded, you can customize it through <% = docname%> from row, as follows

<%

Response.setHeader ("Content-Disposition", "Attachment; FileName = <% = DOCNAME%>. DOC");

%>

This provides a prompt information for user choices as shown below.

Tips: If the programmer needs to design a well-inform in Word document, you can copy the Word format and paste into FrontPage, and take the HTML code to the JSP page.

2 Output Word entities in the existing database in the client

Here only discusses the Word document entity in the blob field in the block field in Oracle. The class getBlobbean is called, which provides the BLOB function from Oracle, the code is as follows:

Package Yourpackage;

Import javax.servlet. *;

Import javax.servlet.http. *;

Import java.io. *;

Import java.util. *;

Import oracle.sql. *;

Import beans.yourbeanpackage. getblobbean;

/ **

*

Title:

*

description:

*

Copyright: Copyright (C) 2004

*

company:

* @Author NOT Attributable

* @version 1.0

* /

Public class getblobservlet1 extends httpservlet {

/ / Set the output content type, this setting is important, otherwise the client browser cannot identify the output, causing the downloaded dialog box.

Private static final string content_type = "Application / msword; charset = GB2312";

// Initialize Global Variables

Public void init () throws servletexception {}

// Process the http get request

Public void doget (httpservletRequest request, httpservletResponse response) throws servletexception, ioException {

Response.setContentType (Content_Type);

Perform (Request, Response);

}

Public void Perform (httpservletRequest Request, httpservletResponse response) {

Try {

// This class function is from Oracle crying out BLOB entity

GetBlobbean getblob = new getblobbean ();

OutputStream Sos = response.getOutputStream ();

Getblob.connfunction ();

Oracle.sql.blob blob = getblob.getblob ("CEHUI");

// Output Word document

IF (blob! = null) {

InputStream Pi = blob.getbinaryStream ();

INT blobsize = (int) blob.length ();

Byte [] blobbytes = new byte [blobsize];

INT BYTESREAD = 0;

While ((bytesRead = pi.read (blobbytes))! = -1) {

SOS.WRITE (blobbytes, 0, bytesread);

}

pi.close ();

Sos.flush ();

Sos.close ();

}

Getblob.dropConnfunction ();

} catch (exception e) {

System.out.println (E.TOString ());

}

}

// Clean Up Resources

Public void destroy () {

}

}

The above two methods are that I have been summarized by friends from all their friends on 9CBS during the development process. Now I will return to everyone to help everyone.

转载请注明原文地址:https://www.9cbs.com/read-6211.html

New Post(0)