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

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...

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...

Contoh Normalisasi, Relasi Antar Tabel, Kamus Data dan Pembuatan Database Sistem Informasi Klinik atau Rumah Sakit

Assalamu'alaikum... Mencoba berbagi lagi sambil nunggu waktu buka puasa, 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 disini dari pembuatan Normalisasi, Relasi Antar Tabel, Kamus Data dan Pembuatan Database Sistem Informasinya. Pembahasan sebelumnya tentang Contoh Analisis dan Perancangan Sistem Informasi Klinik atau Rumah Sakit (Diagram Konteks, DFD/DAD, Flowchart System) sudah irna posting lebih dulu kok tinggal klik aja link nya tapi jangan lupa Skip Add yah tunggu 5 detik ajah hehee... Yupzt berikut hasil screen shoot gambar-gambarnya untuk normalisasi sampai kamus data nya : >> Bentuk Tidak Normal (Unnormal) : >> Bentuk Normal Pertama : >> Bentuk Normal kedua : >> Bentuk Normal Ketiga : >> Relasi Antar Tabel : >> Kamus Data : Tabel 4. 1 Pengguna No Fie...