I am having probelms in using session.putValue and getValue I am authorizing the users with their username and password. Once it is sucessful i am forwarding the user to a Welcome.jsp page. I am trying to put the userId information in the LoginHandler.jsp page with the help of session.putValue() and am trying to retreive it from Welcome.jsp page through session.getValue(). But i am facing an error "Invalid cursor state" What does this mean. I want to know what could be worn in this.I am also sending u the code for both the pages LoginHandler.jsp <%@ page session="true" %> <%@ page import="java.sql.*" %> <%@ page import="java.util.*" %> <%@ page import="java.io.*" %> <%@ page import="java.lang.String" %> <% String userId = request.getParameter("userId"); String password = request.getParameter("password"); %> <%String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String url = "jdbc dbc:Resume"; Class.forName(driver); Connection con=null; try{ con=DriverManager.getConnection(url); String query="SELECT * FROM Password " +"WHERE Ssn ="+userId+" AND Password='"+password+"'"; Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query); String query1="SELECT Ssn FROM Profile WHERE Ssn ="+userId; Statement stmt1=con.createStatement(); ResultSet rs1=stmt1.executeQuery(query1); if (rs.next()){ session.putValue("login",userId); if (rs1.next()){ %> <jsp:forward page="Welcome.jsp"/> <% }else{ %> <jsp:forward page="profile.html"/> <% } %> <% }else{ %> <jsp:forward page="Login.jsp"/> <% } rs.close(); rs=null; rs1.close(); rs1=null; stmt.close(); stmt=null; stmt1.close(); stmt1=null; } finally{ if(con!=null){ con.close();} } %>
session.putValue() and session.getValue(String) are deprecated as of Servlet 2.2 -- they have been replaced by session.setAttribute() and session.getAttribute(String) Try using those and see if that helps.
I am not sure if this is the answer.. but it could well be.. In welcome.jsp (u have written) ---- ResultSet rs=stmt.executeQuery(query); %> <b>Welcome<%= rs.getString("FirstName") %> <%=rs.getString("LastName") %> <% ---------- just after opening the resultset u have not used rs.next() rs.next() does 2 things 1) Returns a boolean which tells you whether it a record exist in the cursor 2) It advances the cursor pointer to the next record. Just after getting the resultset the pointer is before the first record in the resultset and hence I think therein lies ur problem...
vikram nalagampalli
Ranch Hand
Joined: Oct 08, 2001
Posts: 91
posted
0
I tried using the setAttribute() and getAttribute() and i am still encountering with the same error "Invalid Cursor State" Can somebody figure out what is worng. Regads and thanks vikram
Originally posted by Jessica Bradley: session.putValue() and session.getValue(String) are deprecated as of Servlet 2.2 -- they have been replaced by session.setAttribute() and session.getAttribute(String) Try using those and see if that helps.
vikram nalagampalli
Ranch Hand
Joined: Oct 08, 2001
Posts: 91
posted
0
Thanks a lot abraham, It solved my problem. Regards, vikram
Originally posted by Abraham Jacob: I am not sure if this is the answer.. but it could well be.. In welcome.jsp (u have written) ---- ResultSet rs=stmt.executeQuery(query); %> <b>Welcome<%= rs.getString("FirstName") %> <%=rs.getString("LastName") %> <% ---------- just after opening the resultset u have not used rs.next() rs.next() does 2 things 1) Returns a boolean which tells you whether it a record exist in the cursor 2) It advances the cursor pointer to the next record. Just after getting the resultset the pointer is before the first record in the resultset and hence I think therein lies ur problem...
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.