1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
package com.runqian.servlet;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.raqsoft.report.model.ReportDefine;
import com.raqsoft.report.usermodel.Context;
import com.raqsoft.report.usermodel.Engine;
import com.raqsoft.report.usermodel.IReport;
import com.raqsoft.report.usermodel.ParamMetaData;
import com.raqsoft.report.util.ReportUtils;
publicclassExportToExcel extends HttpServlet {
/**
* Constructor of the object.
*/
public ExportToExcel() {
super
();
}
/**
* Destruction of the servlet. <br>
*/
publicvoid destroy() {
super
.destroy();
// Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has itstag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
publicvoiddoGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException {
Stringreport = request.getParameter(
"rpx"
);
Stringyear = request.getParameter(
"year"
);
//保证报表名称的完整性
int iTmp = 0;
if
( (iTmp =report.lastIndexOf(
".rpx"
)) <= 0 ){
report= report +
".rpx"
;
iTmp= 0;
}
StringreportFile = request.getSession().getServletContext().getRealPath(
"/reportFiles/"
+report);
Contextcxt = newContext();
try
{
ReportDefinerd = (ReportDefine)ReportUtils.read(reportFile);
cxt.setParamValue(
"year"
, year);
Engineengine = newEngine(rd, cxt);
//构造报表引擎
IReportiReport = engine.calc();
//运算报表
ReportUtils.exportToExcel(
"D:\\result.xls"
,iReport,
true
);
}
catch
(Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has itstag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
publicvoiddoPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException {
response.setContentType(
"text/html"
);
PrintWriterout = response.getWriter();
out.println(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML4.01 Transitional//EN\">"
);
out.println(
"<HTML>"
);
out.println(
" <HEAD><TITLE>A Servlet</TITLE></HEAD>"
);
out.println(
" <BODY>"
);
out.print(
" This is"
);
out.print(
this
.getClass());
out.println(
", using the POST method"
);
out.println(
" </BODY>"
);
out.println(
"</HTML>"
);
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
publicvoid init() throws ServletException {
// Put your code here
}
}
|