Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Urrgent Pls Advice as soon as possible

 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();}
}
%>

Welcome.jsp
<%
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:Resume";
Class.forName(driver);
Connection con=null;
String userId = (String)session.getValue("login");
try{
con=DriverManager.getConnection(url);
String query="SELECT LastName, FirstName FROM Profile WHERE Ssn="+userId;
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
%>
<b>Welcome<%= rs.getString("FirstName") %> <%=rs.getString("LastName") %>
<%
rs.close();
rs=null;
stmt.close();
stmt=null;
}
finally{
if(con!=null){
con.close();}
}
%>
</BODY></HTML>
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abraham Jacob
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic