Skip to main content

Make Excel Reports of JSP ( Java Web )

Make Excel Reports of JSP ( Java Web )
The following steps:
1.    Create a new project , or if you already have a project that is ready to be used for the 
        practice of opening its first project in Netbeans .
2.    Then create a new jsp files also for export to excelnya code in the usual way right-click Web Pages - Add New - select JSP and then assign a file name with lapObat ( for 
      example, that you want to create the report is a report drug data ) and then finish .
3.    Once the file is open jsp edit the source code as follows :
 
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="java.sql.*" %>
<%@page import="java.io.*" %>
<html>
<head>
<title>Display data from MySQL</title>
</head>
<body>
<h2>Laporan Data Obat</h2>
<%
try {
//deklaration url database
String url = "jdbc:mysql://localhost:3306/sik";
Connection con = null;
Statement stat = null;
ResultSet rs = null;
//load jdbc driver
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url, "root", "");
stat = con.createStatement();
//make query
String query = "Select * from obat";
rs = stat.executeQuery(query);
%>
<%
String exportToExcel = request.getParameter("exportToExcel");
if (exportToExcel != null
&& exportToExcel.toString().equalsIgnoreCase("YES")) {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline; filename="
+ "Obat.xls");
}
%>
<table border="1">
<tr>
<th>Kode Obat</th>
<th>Nama Obat</th>
<th>Harga Obat</th>
</tr>
<% while (rs.next())
{
%>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
</tr>
<%
}
%>
<%
//close conection
rs.close();
stat.close();
con.close();
}
catch (Exception ex)
{
out.println ("Unable to connect to database");
}
%>
</table>
</body>
</html>

Important!!!
Adjust the database name and table name with the database and tables belonging to 
friends own
 
4.    Back On index.jsp file or files jsp friends who want given link Excel reports and edit the 
source code as follows :

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Praktek Membuat Laporan Excel dari JSP (Java Web)</h1>
<h3>By. IRNAWATI</h3>
<br> <a href="lapObat.jsp?exportToExcel=YES">Laporan Excel</a> <br>
</body>
</html>

5.    Do not forget Add Lib Driver Libraries MySQL her so that his views as follows :

6.    If you've tried to run the program , had I Alhamdulillah smoothly without error so that the view page is initially as follows :

 

               If the link is clicked , the Excel report will download excelnya file , and then click OK

 

               and if the file is opened excelnya the results as follows :

 

               NB : if it appears a text box warning just click Yes .


the interest in his e - Book could be in line e - Book , there are usually looking for his project too ,
please Download Database Project + FREE ( using Netbeans IDE 7.2 and XAMPP / WAMP )

Comments

Popular posts from this blog

Tutorial atau Cara Menambahkan Palette yang Belum Tersedia di Netbeans

Ini juga gak kalah mudahnya, tapi semoga bermanfaat karena berbagi itu gak ada yang sia-sia. (yang di praktekkan menambahkan palette jDateTimePicker. Berikut langkah-langkahnya : 1.      Pada menu bar Tools pilih Palette > pilih Swing/AWT Components. 2.        Setelah muncul tampilan seperti dibawah klik Add From Jar. 3.        Cari file Calendar.jar yang sudah anda download/simpan, jika belum punya silahkan temen2 download dulu di >> Download Kemudian klik Next. 4.        Pilih Available Components JDateTimePicker, Kemudian klik Next. 5.        Pilih palette categories tempat untuk menyimpan hasil penambahan palette jDateTimePicker nya, disini saya pilih Swing Controls Klik Finish. Form yang masih terbuka close saja.  6.        Cek di palette Swing Contr...

Source Code Program Sistem Informasi Rekam Medis Pada KLinik Rawat Jalan Berbasis Java Web (JSP, Servlet, JSTL)

Bismillah... Mencoba lagi meskipun masih sederhana.. Source code program ini menggunakan Netbeans 7.2 berbasis java web (JSP, JSTL, Servlet) dan menggunakan perintah SQL inner join untuk mempermudah User dalam menggunakan sistem/aplikasi ini. Bisa melakukan simpan, edit, hapus dan pencarian data. Design web nya menggunakan bahasa HTML dan CSS. Berikut hasil screen shoot tampilan program setelah di Run di Google Chrome : 1. Tampilan Home/Beranda ketika pertama kali di Run. 2. Tentang Program (Tampilan yang muncul ketika klik Menu About.) 3. Input Data Obat (tampilan ketika menu Obat di klik) 4. Input Data Dokter (tampilan ketika menu Dokter di klik) 5. Input Data Petugas (tampilan ketika menu Petugas di klik) 6. Input Data Pasien (tampilan ketika menu Pasien di klik) 7. Input Data Tarif Tindakan (tampilan ketika menu Tarif Tindakan di klik) 8. Input Data Pemberian Obat (tampilan ketika menu Pemberian Obat di klik)     Berrelasi dengan tabel Obat...

Source Code Program Aplikasi/Software Sewa Tanah Pemerintah Desa/Lungguh Desa ( JAVA DEKSTOP )

Awalnya soal UTS Pemrograman Java 1 di semester 4 hehee... Design tampilan menggunakan jTatto, sebelum program di Run add file jar jTatto nya ke Libraries, caranya ya download dulu file  jTatto.jar  , buka project nya, klik kanan Libraries > pilih Add jar/folder > cari file jTatto.jar > Open. Program ini sudah lengkap dengan inner join tabelnya, login/logout dan cetak laporan/report, Berikut hasil Screen Shoot nya, temen2 silahkan kembangkan sendiri dan ubah designnya sesuai selera masing2! 1. Menu Utama sebelum Login (Sub Menu Login akan berubah menjadi Logout setelah sukses Login) 2. Form Login 3. Menu Utama setelah Login 4. Form Input Data Pegawai 5. Form Input Data Dusun 6. Form Input Data Desa 7. Form Input Data Kecamatan 8. Form Input Data Kabupaten 9. Form Input Data Provinsi 10. Form Input Data Penyewa 11. Form Input Data Pelungguh 12. Form Input Data Tanah 13. Form Input Data Sewa (Penyewaan) 14...