Hi;
The below page validates the user. if the groupid of the user is null into the database,it forward the user to accessdenied.jsp page. The below code works fine without closing rs
If i had tried to close rs.close(); it show the compile error: rs might not have been initialised.
and without close, it does not work for the accessdenied.jsp
<%--
Document : as
Created on : Jul 26, 2008, 12:41:17 PM
Author : user1
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language ="java" %>
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*,java.io.*,java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String userid=request.getParameter("userid");
String password=request.getParameter("password");
InitialContext context = new InitialContext();
DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/mynewdatabase");
Connection conn = ds.getConnection();
context.close();
Statement stmt=conn.createStatement();
ResultSet rs;
try {
rs=stmt.executeQuery("select groupid from user where emailid='"+userid+"' and Password='"+password+"'");
%>
<% while(rs.next())
{
%>
<% String groupId = rs.getString("groupid");
out.println(groupId);
if ( groupId==null )
{
out.println("Invalid User");
%>
<jsp:forward page="/AccessDenied.jsp" />
<%
}
else
{
out.println("Valid User");
%>
<jsp:forward page="/try.jsp" />
<% }
}
}
finally
{
if (rs != null)
{
rs.close();
rs = null;
}
if (stmt != null)
{
stmt.close();
stmt = null;
}
}
%>
</body>
</html>
2. Can i access the variable groupid in try.jsp page by request.getparameter() method.
If not then can any have the alternative way for accessing same variable in try.jsp page.
Thanks and Regards
Haresh