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

source code program pembuatan sistem informasi posyandu menggunakan netbeans IDE 7.2 berbasis java web

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, dan juga ada fasilitas Presensi Petugas. Berikut hasil screen shoot tampilan program : 1. Menu Utama 2. Menu input data Berat Badan Bayi Timbang 3. Menu input data Petugas 4. Menu input data Posyandu (inner join dengan tabel data Kelurahan) 5. Menu input data Puskesmas (inner join dengan tabel data Kecamatan) 6. Menu input data Kelurahan (inner join dengan tabel data Puskesmas) 7. Menu input data Kecamatan 8. Menu input data Ibu (inner join dengan tabel data Posyandu) 9. Menu input data Anak (inner join dengan tabel data Ibu) 10. Menu input data Ibu Hamil (inner join dengan tabel data Ibu) 11. Menu input data Layanan Anak ( inner join dengan tabel data Anak) 12. Menu Presensi Petugas (inner join d...