|
|
Hi,
I have this application in which I am using session to trak different types of user going to different pages.
There are 2 kinds of users. The admin, if log in successful, will go to Update.jsp. If it is member, they will be redirected to Addmember.jsp. If they are not in the database, they will be redirected to login again.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Statement stmt = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:SESSIONODBC";
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
} catch (Exception e) {
System.out.println(e.getMessage());
}
rs = stmt.executeQuery("Select * from Staff");
%>
<%
String accessType=(String)session.getAttribute("login");
if(accessType==null){
response.sendRedirect("login.jsp");
}
else if(accessType.equals("member")){
response.sendRedirect("AddMember.jsp");
}
else{
out.println("Update.jsp");
}
%>My html page is:-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="Session.jsp">
<tr>
<td>Userid</td>
<td><input type="text" id="userid" name="login" ></td>
</tr>
<tr>
<td>password</td>
<td><input type="text" id="password" name="password" ></td>
</tr>
<tr>
<td>accessType</td>
<td><input type="text" id="access" name="access" ></td>
</tr>
<tr>
<td align="right"><input type="submit" value="Submit" />
</tr>
</table>
</form>
</body>
</html>My database field consists of the following :-
userid password accessType