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

Source code program SIMRS/Rekam Medis (khusus poliklinik ibu dan anak) dengan java netbeans #tambahan2

Ada tambahan pada Source code program beserta database nya sudah ready 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. Tampilan sebelum login 2. Tampilan input data admin 2. Tampilan input data pasien ibu 3. Tampilan input data pasien mati ibu 4. Tampilan input data pasien bayi 5. Tampilan input data pasien mati bayi 6. Tampilan input data penyakit 7. Tampilan input data kamar 8. Tampilan input data tindakan 9. Tampilan input data rawat inap bayi 10. Tampilan input data rawat inap ibu 11. Tampilan input data imun...

Contoh Analisis dan Perancangan Sistem Informasi Klinik atau Rumah Sakit (Diagram Konteks, DFD/DAD, Flowchart System)

Assalamu'alaikum... Mencoba berbagi lagi, irna pengen bahas tentang bagaimana merancang sistem (analisys system) pembuatan sebuah Sistem Informasi Klinik atau bisa juga Rumah Sakit tapi dalam lingkup kecil. Yang mau irna bahas dari pembuatan Diagram Konteks, Data Flow Diagram (DFD) atau Diagram Alir Data (DAD) dari level 1 sampai level 3 dan Flowchart System nya. Yupzt berikut hasil screen shoot gambar-gambarnya : >> Diagram Konteks atau Kontext Diagram Sistem Informasi Klinik atau Rumah Sakit : >> DFD (Data Flow Diagram) atau DAD (Diagram Alir Sistem Sistem) Level 1 Sistem Informasi Klinik atau Rumah Sakit : >> DFD (Data Flow Diagram) atau DAD (Diagram Alir Sistem Sistem) Level 2 Input Data Sistem Informasi Klinik atau Rumah Sakit : >> DFD (Data Flow Diagram) atau DAD (Diagram Alir Sistem Sistem) Level 2 Proses atau Transaksi Sistem Informasi Klinik atau Rumah Sakit : >> DFD (Data Flow Diagram) atau DAD (Diagram Ali...

Membuat Login Multiuser atau Multi Level User (berbeda hak akses) Java Dekstop

Bismillah.. Dalam pembuatan system, terutama yang berbasis client-server tentu nya hak akses setiap petugas berbeda, oleh karena itu dibutuhkan login yang multiuser atau multi level user. Berikut langkah-langkah pembuatannya pada pemrograman java desktop NetBeans IDE.   1.       Design tampilan form utama seperti pada gambar di bawah : #Sub menu Login akan berubah otomatis menjadi Logout ketika Login sudah berhasil. #semua tombol/button tidak aktif (enable=false). 2.         Buat sebuah database (saya menggunakan MySQL), berikut contoh struktur database untuk table admin nya : 3.         Jangan lupa Add Library MySQL JDBC Driver nya, caranya tinggal klik kanan pada Libraries > Pilih Add Library sehinggan muncul tampilan berikut : Jika MySQL JDBC Driver nya belum ada, klik tombol Import dan cari file MySQL JDBC Driver nya kemudian pilih filenya lalu tekan Ok. Se...