2015-12-03 65 views
-4
<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> 

這裏用戶輸入的PDF文檔form.now我想獲得用戶輸入使用碧玉reports.i PDF報表正在使用HTML ireport設計器5.6.0。我應該使用哪些庫,以及如何獲取報告。我只使用jsp servlet進行Web應用程序,沒有任何frameworks.thanks。如何顯示僅使用ireports(碧玉報告)servlet和jsp

+0

這是廣泛的(您要求提供一個指導您如何設置您的jsp servlet,生成報告的java代碼以及如何開發jrxml代碼ecc)。您需要了解jasper報告如何工作(下載JasperSoftStudio等IDE),如何使用jsf servlet(導出爲pdf)以及何時使用.jrxml或java存在特定問題,請發佈您正在使用的代碼,你的輸出是什麼,你想要的結果是什麼 –

回答

1

在這裏,我找到了答案傢伙。感謝您的答覆。首先我會告訴你文件夾結構。

enter image description here

首先你要在上面顯示庫添加到您的應用程序。 然後這是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包看到控制器class.As包含控制器類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; 
} 

}

現在你做什麼more.create報告是下一個。 我已經使用iReport 5.6.0創建了UserDeatails.jasper報告。 使用iReport創建您的報告的基本結構後,右鍵點擊報告轉到 - >屬性 - >語言(選擇java的語言) 其他明智的報告可能會出現錯誤。 然後將report.and編譯後的.jasper文件編譯爲項目,如文件夾結構中所示。

我將添加碧玉報告的圖像。

enter image description here

這是所有guys.Again感謝您的答覆。

+0

考慮接受你自己的答案... –