| Author |
Thread |
| Login jsp servlet |
|
Posted in tutorial: Combining Servlets, JSP, and JavaBeans |
· vb_java
Joined: 19 Jun 2004 Total Posts: 1 |
Login jsp servlet Posted: 19 Jun 2004
i want to login using Jsp, servlet and beans to connect mysql server. this server running under using tomcat. I cannot find the solution for this login function. do anyone have this solution
computer science need alot knowledge in programming, so one of have to gain the knowledge
|
· yassoura
Joined: 18 Oct 2004 Total Posts: 1 |
login Posted: 18 Oct 2004
Hi, i'm in the same problem with you and i want to know if you've found a solution to it . Thank you :-)
|
· gendull
Joined: 19 Dec 2006 Total Posts: 3 |
login.jsp Posted: 19 Dec 2006
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.io.*,java.util.*" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>LOGINE</title> <style type="text/css"> <!-- .style1 { font-size: large; font-weight: bold; } .style3 {color: #0000FF} --> </style> </head>
<body> <!-- <jsp:include page="includez/atas.jsp" /> --> <p> </p> <form id="form1" name="form1" method="post" action=""> <table width="367" border="1" align="center"> <tr> <td colspan="2"><div align="center" class="style1">Silakan Masukkan User Dan Password </div></td> </tr> <tr> <td width="99"><strong>User</strong></td> <td width="252"><label> <input name="t1" type="text" id="t1" size="40" maxlength="15" /> </label></td> </tr> <tr> <td><strong>Password</strong></td> <td><label> <input name="t2" type="password" id="t2" size="40" maxlength="32" /> </label></td> </tr> <tr> <td colspan="2"><label> <div align="center"> <input type="reset" name="Reset" value="Reset" /> <input type="submit" name="Submit" value="Login" /> </div> </label></td> </tr> </table> <% try { if(request.getParameter("t1").length()==10) { %> <jsp:forward page="omhs.jsp" /> <% } else if(request.getParameter("t1").length()==9) { %> <jsp:forward page="opeg.jsp" /> <% } else { %> <jsp:forward page="login.jsp"/> <% } } catch(Exception er) {} //out.println(er.toString());} %> <table width="152" border="0" align="center"> <tr> <td><div align="center"><strong><a href="index.jsp" class="style3">HOME</strong></div></td> </tr> </table> </form> <p> </p> </body> </html>
|
· gendull
Joined: 19 Dec 2006 Total Posts: 3 |
opeg.jsp Posted: 19 Dec 2006
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.io.*,java.util.*" buffer="8kb" autoFlush="true" errorPage="" %>
<% try {
String sql = "select * from pegawai where nip ='"+request.getParameter("t1")+"'"; Class.forName("org.postgresql.Driver"); Connection koneksi = DriverManager.getConnection("jdbc:postgresql://10.107.154.11:5432/mmua", "arief", "ariefjuga"); out.println("konek rek"); Statement stmj = koneksi.createStatement(); //try { // Menguji apakah data ada di database ???? ResultSet rst = stmj.executeQuery(sql); rst.next(); String qrypass=rst.getString("passworde"); //ambil password dari hasil query String txpass=request.getParameter("t2"); //ambil nilai tx2 dari form login if(txpass.equals(qrypass)) { String ambilnip = rst.getString("nip"); String ambilnama = rst.getString("namapegawai"); String ambilgroup = rst.getString("idpeg"); //if(ambilnip==null) ambilnip=""; session.setAttribute("nomerp", ambilnip); session.setAttribute("namanyap", ambilnama); session.setAttribute("namagroup", ambilgroup); //out.println("siiip"); response.sendRedirect( "main.jsp" ); stmj.close(); koneksi.close(); } else { //response.sendRedirect( "sdhada.jsp" ); out.println("Can't query"); stmj.close(); koneksi.close(); } }catch (Exception err) { out.println(err.toString()); out.println("Can't connect to server, Database Server is death"); } %>
|
· gendull
Joined: 19 Dec 2006 Total Posts: 3 |
i use postgresql database Posted: 19 Dec 2006
i use postgresql database.
if you use any database, please copy jdbc driver to tomcat library and edit source connection >>> Class.forName("org.postgresql.Driver"); Connection koneksi = DriverManager.getConnection("jdbc:postgresql://10.107.154.11:5432/mmua", "arief", "ariefjuga");
with your database connection.
sorry my english is bad.
good luck
|