<form class="form-horizontal" class="form-inline" id="divfundtransferownaccounts" method="post" action="FundTransferToOwnAccounts" onsubmit="return passwordCheck(document.getElementById('password').value)" style="margin-left: px;margin-right: 5px;">
<div class="form-group">
<label class="control-label col-sm-5">Enter your password To Proceed the Transaction*</label>
<div class="col-sm-6">
<input name="confirmfacnumber" id="idconfirmfacnumber" class="form-control input-sm">
<input name="confirmtacnumber" id="idconfirmtacnumber" class="form-control input-sm">
<input name="confirmcurrencyamount" id="idcurrencyamount" class="form-control input-sm">
<input name="confirmcurrencytype" id="idcurrencytype" class="form-control input-sm">
<input name="confirmfacnarration" id="idconfirmfacnarration" class="form-control input-sm">
<input name="confirmtacnarration" id="idconfirmtacnarration" class="form-control input-sm">
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-5 col-xs-10">
<button type="submit" class="btn btn-primary " style="padding-left: 25px;padding-right: 25px;">Proceed</button>
<button type="button" class="btn btn-primary " style="padding-left: 25px;padding-right: 25px;" onClick="goBack()">Back</button>
</div>
</div>
</form>
这是html form.now我想使用jasper reports.i使用ireport设计器5.6.0获取用户输入pdf报告。我应该使用的库是什么以及我应该怎样做才能获得report.i我只使用jsp servlet用于Web应用程序而没有任何frameworks.thanks。
答案 0 :(得分:1)
在这里,我找到了答案的人。感谢您的回复。 首先,我将向您展示文件夹结构。
首先,您必须将上面显示的库添加到您的应用程序中。 然后这是jsp文件代码。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="resources/bootstrap/bootstrap-theme.css"/>
<link rel="stylesheet" type="text/css" href="resources/bootstrap/bootstrap-theme.min.css"/>
<link rel="stylesheet" type="text/css" href="resources/bootstrap/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="resources/bootstrap/bootstrap.min.css"/>
<title>Jasper Report Example</title>
</head>
<body>
<form class="form-horizontal" class="form-inline" method="post" action="GetUserData" style="margin-left: px;margin-right: 5px;">
<div style="padding-bottom: 25px;"></div>
<div class="form-group">
<label class="control-label col-sm-3">First Name*</label>
<div class="col-sm-6">
<input name="firstname" id="idfirstname" class="form-control input-sm">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Last Name*</label>
<div class="col-sm-6">
<input name="lastname" id="idlastname" class="form-control input-sm">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Email*</label>
<div class="col-sm-6">
<input name="email" id="idemail" class="form-control input-sm">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Phone Number*</label>
<div class="col-sm-6">
<input name="phonenumber" id="idphonenumber" class="form-control input-sm">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">NIC*</label>
<div class="col-sm-6">
<input name="nic" id="idnic" class="form-control input-sm">
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-5 col-xs-10">
<button type="submit" class="btn btn-primary " style="padding-left: 25px;padding-right: 25px;">Sumbit</button>
</div>
</div>
</form>
</body>
正如您在文件夹结构中看到的那样,您必须制作pojo类。 这是UserDetails.java pojo类。
public class UserDetails {
private String firstname;
private String lastname;
private String email;
private String phonenumber;
private String nic;
/**
* @return the firstname
*/
public String getFirstname() {
return firstname;
}
/**
* @param firstname the firstname to set
*/
public void setFirstname(String firstname) {
this.firstname = firstname;
}
/**
* @return the lastname
*/
public String getLastname() {
return lastname;
}
/**
* @param lastname the lastname to set
*/
public void setLastname(String lastname) {
this.lastname = lastname;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return the phonenumber
*/
public String getPhonenumber() {
return phonenumber;
}
/**
* @param phonenumber the phonenumber to set
*/
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
/**
* @return the nic
*/
public String getNic() {
return nic;
}
/**
* @param nic the nic to set
*/
public void setNic(String nic) {
this.nic = nic;
}
}
现在创建简单的pojo类后,你必须创建控制器类。如文件夹结构中所示,report.controller包中包含控制器类GetUserData.java servlet文件。
这是GetUserData.java servlet文件代码。
public class GetUserData extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, JRException {
//response.setContentType("application/pdf");
//PrintWriter out = response.getWriter();
String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
String email = request.getParameter("email");
String phonenumber = request.getParameter("phonenumber");
String nic = request.getParameter("nic");
HashMap parametermap = new HashMap();
parametermap.put("firstname", firstname);
parametermap.put("lastname", lastname);
parametermap.put("email", email);
parametermap.put("phonenumber", phonenumber);
parametermap.put("nic", nic);
GenerateReport generatereportinstance = new GenerateReport();
byte[] outputarray = generatereportinstance.GenerateReport(request.getServletContext(),parametermap);
OutputStream outStream = response.getOutputStream();
response.setHeader("Content-Disposition", "filename=UserDetailsReport.pdf");
response.setContentType("application/pdf");
response.setContentLength(outputarray.length);
outStream.write(outputarray, 0, outputarray.length);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (JRException ex) {
Logger.getLogger(GetUserData.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (JRException ex) {
Logger.getLogger(GetUserData.class.getName()).log(Level.SEVERE, null, ex);
}
}
现在最后一个编码部分。在包report.utility包中创建业务逻辑。 这是GenerateReport.java类文件代码。
public class GenerateReport {
JasperPrint jasperPrint = null;
public byte[] GenerateReport(ServletContext servletContext, HashMap parametermap) {
byte[] outputFile = null;
try {
try {
String file = servletContext.getRealPath("/WEB-INF/report/UserDetails.jasper");
System.out.println("Generating PDF Report");
JasperPrint jasperPrint =JasperFillManager.fillReport(file,parametermap,new JREmptyDataSource());
outputFile =JasperExportManager.exportReportToPdf(jasperPrint);
System.out.println("User Details.pdf has been generated!");
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return outputFile;
}
}
现在你要做更多的事情。创建报告是下一个。 我使用 iReport 5.6.0。创建了UserDeatails.jasper报告 使用iReport创建报告的基本结构后, 右键点击报告转到 - &gt;属性 - &gt;语言(在语言中选择 java ) 其他明智的报告可能会出错。 然后将report.and编译的.jasper文件编译到项目中,如文件夹结构所示。
我将添加jasper报告的图像。
这就是所有人。非常感谢您的回复。