📄 compileservletdata.java
字号:
package com.hhkj.jasper;
/**
* @author wzj
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
import net.sf.jasperreports.engine.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CompileServletData extends HttpServlet {
/**
*
*/
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
ServletContext context = this.getServletConfig().getServletContext();
/*
* 2004-12-17 add jasper.reports.compile.class.path By default,
* ^JasperReports uses the current JVM classpath to compile the report
* class (java.class.path system property). To customize this report
* compilation process, ^JasperReports lets you override the default
* behavior by supplying a value to the
* jasper.reports.compile.class.path system property, which will be used
* as classpath for the report class compilation.
*/
System.setProperty("jasper.reports.compile.class.path", context
.getRealPath("/WEB-INF/lib/jasperreports-1.1.1.jar")
+ System.getProperty("path.separator")
+ context.getRealPath("/WEB-INF/classes/"));
/*
* 2004-12-17 add jasper.reports.compile.temp The temporary location for
* the files generated on-the-fly is by default the current working
* directory. It can be changed by supplying a value to the
* jasper.reports.compile.temp system property.
*/
System.setProperty("jasper.reports.compile.temp", context
.getRealPath("/jasper/reports/"));
try {
String fileName = request.getParameter("fileName");
String path = "/jasper/reports/" + fileName + ".jrxml";
System.out.println(path);
JasperCompileManager.compileReportToFile(context.getRealPath(path));
} catch (JRException e) {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out
.println("<title>JasperReports - Web Application Sample</title>");
out
.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out
.println("<span class=\"bnew\">JasperReports encountered this error :</span>");
out.println("<pre>");
e.printStackTrace(out);
out.println("</pre>");
out.println("</body>");
out.println("</html>");
return;
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>JasperReports - Web Application Sample</title>");
out
.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out
.println("<span class=\"bold\">The XML report design was successfully compiled.</span>");
// out.println("test.xml compile to test.jasper");
out.println("</body>");
out.println("</html>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -