Kaskus

Tech

hooligans46Avatar border
TS
hooligans46
<ask><help>error di Java server page(JSP)
permisi agan2 para sesepuh programmer stuff emoticon-Big Grin
ane ada sedikit problem nih,jadi lagi belajar JSP(java server page) untuk form login yang kekoneksi dengan database
disini ane punya3 file "Login.jsp","doLogin.jsp", dan "welcome.jsp"
sumpah ane stuck banget,mohon koreksi +bantuannya gan emoticon-Big Grin
Login.jsp
Code:


<html>
<head>
[removed]
function ccheck()
{
uid=document.f1.uid.value;
cpass=document.f1.cpass.value;

if(uid=="" || uid==null)
{
alert("Plz. Enter Your User ID");
document.f1.uid.focus();
return false;
}
if(cpass=="" || cpass==null)
{
alert("Plz. Enter Your Password");
document.f1.cpass.focus();
return false;
}
return true;
}
[removed]
<title>Login Page in Jsp</title>
</head>
<body>
<h2>LOGIN PAGE IN JSP</h2>
<form id="f1" name="f1" action="doLogin.jsp" method="post">
<table>
<tr>
<td><b>User ID</b></td>
<td><input name="uid" type="text"/></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input name="cpass" type="password"/></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /> </td>
<td><input type="reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>
</html>



doLogin.jsp

Code:

<%@ page import="java.sql.*" %>
<%! String cid="",pass="";Connection con; %>
<%
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:8080/test","root","");
Statement stmt=con.createStatement();
ResultSet rs;
cid=request.getParameter("uid");
pass=request.getParameter("cpass");
//System.out.println("cid="+cid+" pass="+pass);
rs=stmt.executeQuery("select * from login where userid='"+cid+"' and password='"+pass+"' ");
if(rs.next())
{
session.setAttribute("scid",cid);
con.close();
response.sendRedirect("welcome.jsp");
}
else
{
%>
<html>
<body>
<h1>Invalid UserID or Password</h1>
<jsp:include page="login.html" />
<%
}
%>
</body>
</html>


welcome.jsp
Code:
<%@ page import="java.sql.*" %>
<%! String scid=""; %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Login Page</title>
</head>
<body>
<%
scid=(String)session.getAttribute("scid");
%>
<div id="welcome">
<h2><span>Welcome:::<strong><font color='Red'><%= scid %></font></strong></span></h2>
</div>
</body>
</html>


ane ngerunning lewat maven,tapi pas masukin user sama password sesuai dengan database malah error emoticon-Busa

errornya
Spoiler for error:


skema database
Spoiler for database:
0
1.8K
11
GuestAvatar border
Komentar yang asik ya
Urutan
Terbaru
Terlama
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan