Belajar Membuat Template
Nama : Ardhy Irawan
Nim : 1111511661
1. Pada menu ini anda dihadapkan pada sebuah form untuk memasukkan username dan password, silahkan masukkan username dan password anda untuk dapat melanjutkan kelangkah selanjutnya.
a.index.jsp
<%--
Document : index
Created on : Mar 26, 2016,
12:46:47 PM
Author : ARDHY
IRAWAN
--%>
<%@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>
<style
type="text/css" rel="stylesheet">
#left{
float: left;
width: 20%;
border-style: groove;
background-color: aqua;
height: 300px;
}
#right{
margin-left: 300px;
width: 590px;
border-style: groove;
height: 300px;
}
#header{
width: 66%;
height: 150px;
border-style: groove;
font-family: tahoma;
font-size: 32px;
font-weight: bold;
background-color: background;
}
</style>
<body>
<div
id="konten"></div>
<div
id="header">
<h1>Web Perubahan</h1>
</div>
<div
id="left">
<h3><a href="index.jsp?id=login">Menu
Login</a></h3><br/> <--Untuk memanggil menu login -->
<h3><a href="index.jsp?id=form">Menu Dosen</a></h3><br/> <--Untuk memanggil menu dosen-->
</div>
<div
id="right">
<%
if(request.getParameter("id")==null)
{
out.print("data kosong");
}
else
{
String kode=request.getParameter("id");
if(kode.equals("form"))
{
%>
<jsp:include
page="view/registrasi.jsp" flush="true"/>
<%
}else if(kode.equals("login"))
{
%>
<jsp:include
page="view/login.jsp" flush="true"/>
<%
}
}
%>
</div>
</body>
</html>
------------------------------------------------------------------------------------------------------------
Tampilan
b. login.jsp
<%--
Document : login
Created on : Apr 1, 2016, 2:57:22 PM
Author : ARDHY IRAWAN
--%>
<%@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>
<div id="login"
align="center">
<h1>Login</h1>
<form
action="" method="post"> <--Form Input Login -->
<table>
<tr>
<td>Usename</td>
<td>:</td>
<td><input type="text"
name="username"></td> <--Untuk Input username -->
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="password"
name="pass"></td> <--Untuk Input password -->
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit"
value="Login"></td> <--Button submit untuk proses login -->
</tr>
</table>
</form>
</div>
</body>
</html>
a. registrasi.jsp
<%--
Document : registrasi
Created on : Mar 26, 2016, 12:50:32 PM
Author : ARDHY IRAWAN
--%>
<%@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>
<div id="dosen"
align="center">
<h1>Master
Dosen</h1><br/>
<form
action="registrasi-proses.jsp" method="post"> <--Form Input Registrasi Dosen -->
<table>
<tr>
<td>NIP</td>
<td>:</td>
<td><input type="text"
name="txtnip"><--Untuk Input nip--><input type="submit"
value="Cari"></td> <--Button Cari -->
</tr>
<tr>
<td>Nama</td>
<td>:</td>
<td><input type="text"
name="txtnama"></td> <--Untuk Input nama-->
</tr>
<tr>
<td>Pendidikan</td>
<td>:</td>
<td><select
name="pddk"> <--Untuk pilih Pendidikan-->
<option value="s1">S1</option>
<option value="s2">S2</option>
<option value="s3">S3</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input
type="submit" name="cmdsimpan" value="simpan"> <--Button submit untuk proses simpan-->
<input type="submit"
value="ubah"> <--Button submit untuk proses ubah-->
<input type="submit"
value="hapus"> <--Button submit untuk proses hapus-->
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
-----------------------------------------------------------------------------------------------------------
Tampilan
-----------------------------------------------------------------------------------------------------------
Tampilan
b. registrasi-proses.jsp
<%--
Document : registrasi-proses
Created on : Apr 5, 2016, 8:15:51 PM
Author : ARDHY IRAWAN
--%>
<%@page import="jdbc.Koneksi" %>
<%@page import="java.sql.*" %>
<%
String nip =
request.getParameter("txtnip");
String nama =
request.getParameter("txtnama");
String pddk =
request.getParameter("pddk");
String dapat =
request.getParameter("cmdsimpan");
if(dapat.toString().equals("simpan")){
try{
Koneksi konek =
new Koneksi();
Connection conn =
konek.bukaKoneksi();
Statement stm =
conn.createStatement();
String sql =
"insert into dosen(nip, nama, pendidikan) "
+ "values ('" + nip + "','" + nama + "','"
+ pddk + "')";
stm.executeUpdate(sql); <--Query simpan ke database -->
conn.close();
out.print("Berhasil
disimpan");
out.print("<a
href='index.jsp'>Back</a>");
} catch (Exception e) {
out.print(e);
}
}
%>
5. Koneksi.Java <--Koneksi ke database -->
/*
* To change this license header, choose License Headers in
Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jdbc;
import java.sql.*;
/**
*
* @author 3ch0
*/
public class Koneksi {
public Connection bukaKoneksi()throws SQLException{
Connection connect;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connect=DriverManager.getConnection("jdbc:mysql://localhost:3306/webinclude",
"root", "");
return connect;
}
catch(Exception exc){
}
return null;
}
}
Tidak ada komentar:
Posting Komentar