public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//报表编译之后生成的.jasper文件的存放位置
String type=request.getParameter("type");
String grade=request.getParameter("grade");
String class_1= request.getParameter("class");
String sql="select * from print where type='"+type+"'";
if(!grade.equals("")){
sql=sql+" and grade='"+grade+"'";
}
if(!class_1.equals("")){
sql=sql+" and class='"+grade+class_1+"'";
}
System.out.println(sql);
String path="";
if(type.equals("优秀队员") || type.equals("五小标兵")){
path="print_x";
}
if(type.equals("优秀督导队员") || type.equals("成绩有进步奖")){
path="print_xx";
}
if(type.equals("读书积极分子")){
path="print_xxx";
}
if(type.equals("劳动积极分子")){
path="print_xxxx";
}
String u="/print/"+path;
System.out.println(u);
//String u="/print/print_x.jasper";
File reportFile = new File(this.getServletContext().getRealPath(u));
String url="jdbc:mysql://localhost:3306/jmzc";
try{
Class.forName("com.mysql.jdbc.Driver");
Map parameters = new HashMap();
//parameters.put("SQLSTR",sql); //"SQLSTR"是报表中定义的一个参数名称,其类型为String 型
Connection conn = DriverManager.getConnection(url,"root", "seebig");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
String pp=this.getServletContext().getRealPath(u);
System.out.println(pp);
JasperFillManager.fillReportToFile(pp+".jasper",parameters,new JRResultSetDataSource(rs));
JRViewer jr = new JRViewer(pp+".jrprint",false);
JFrame jf = new JFrame(type);
jf.add(jr);
jf.pack();
jf.setSize(1024, 600);
jf.setVisible(true);
}catch(Exception ex){
ex.printStackTrace();
}
}
这个servlet 中,我使用iReport中JRViewer编写显示打印预览, 当我在客户端的电脑里点击网页中的打印预览,没有任何显示,回头看服务端就有一个显示JRViewer打印预览的程序,为何这样呢?