Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help JSP Loging using session

Can anybody help me out with this code. I am trying to create a login page for JSP using session but it's not working...

this is the code:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page language ="java" import = "java.io.*" import = "java.lang.*" import = "java.sql.*" %>

<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">




JSP Page

Div.Shade{ background:azure; border-top:1px solid darkcyan;border-bottom:1px solid darkcyan; width: 300px; height:50px;float: left}



<% try

{
Connection myConn;
String strUsername = request.getParameter("username");
String strPassword = request.getParameter("password");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
myConn =DriverManager.getConnection("jdbc:odbc:RoomSchedule");

Statement myStatement = myConn.createStatement ();

String strSQL = "SELECT [userID], [password] FROM Administrator";


ResultSet myResult = myStatement.executeQuery(strSQL);

String strUser = myResult.getString("userID");
String strPass = myResult.getString("password");

while(myResult.next())
{
if(strUsername.equals(strUser) && strPassword.equals(strPass))
{
//valid
session.setAttribute("authorized", "yes");
out.println("Login Successful!");
}
else
{
//invalid login
session.setAttribute("authorized", "no");
out.println("Login Fail!");
}
}

myConn.close();
}
catch(Exception e){ }
%>



<%--
This example uses JSTL, uncomment the taglib directive above.
To test, display the page like this: index.jsp?sayHello=true&name=Murphy
--%>
<%--
<c:if test="${param.sayHello}">

Hello ${param.name}!

--%>

LOGIN














Sign In or Register to comment.