Poi is generally used to export reports in projects. However, if you do not want to use a framework, you can use a simple jsp to export reports. It is also very simple to implement. First look at the effect:
Click "Export:
Specific implementation:
First, the iterator source code is as follows on the page list page:
Serial number |
|
Inspection No. |
File No. |
Name |
Gender |
Age |
Mobile phone number |
Positive project results |
|
"/> |
|
|
|
|
|
|
| ">
No matching data found |
Second, click the corresponding action after export to query the list to be exported from the database. (Nothing special)
Public String exportPositiveResult () {if (qureyBean = null) {qureyBean = new SickPeople ();} // this is to convert the check box array to the SQL in condition String [] record_ids = this. getParameterValues ("recordids"); String record_id = stringArray2StringIn (record_ids); qureyBean. setRecord_id (record_id); listsickpeople = recordService. positiveresult (qureyBean, 1, 1000000); this. dictService. setDictName2ListData (listsickpeople, CacheGloba L. DICT_SEX); execlFileName = UncDate. formatDateTime (new Date (), "yyyyMMddHHmmss"); return SUCCESS ;} /*** convert an array separated by commas into an In condition ** @ param str * @ return */public String stringArray2StringIn (String [] recordids) {StringBuffer idsStr = new StringBuffer (); for (int I = 0; recordids! = Null & I <recordids. length; I ++) {if (I! = 0) {idsStr. append (",");} idsStr. append ("'"). append (recordids [I]). append ("'");} return idsStr. toString ();}
Third: the jsp to jump to after the action is executed. (In this special case, there are two points: first, some statements need to be added to the header file. The second page only needs to export the data required by the report, without any js or css) source code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = GBK "pageEncoding =" GBK "%> <% @ taglib prefix =" s "uri ="/struts-tags "%> <% String execlFileName = (String) request. getAttribute ("execlFileName"); response. setHeader ("Content-disposition", "attachment; filename =" + execlFileName + ". xls "); response. setHeader ("Pragma", ""); response. setHeader ("Cache-Control", ""); %>
Health Check System
Serial number |
Inspection No. |
File No. |
Name |
Gender |
Age |
Phone number |
Positive project results |
|
|
|
|
|
|
|
|