-1

I have a login form in JSP. All the login information I'm storing in Oracle database.

For new users they need to register to login. But for the users those who have accounts, as they logs in they will have the option called "Account Setting" where they can edit their basic information.

When user clicks on that link, his account information should be displayed. But I'm not able to retrieve currently logged in user's information from database.

Here is my JSP code to check whether user's account exists or not:

 <%  

try 

{

     String user=request.getParameter("username");

     String pass=request.getParameter("password");

     Class.forName("oracle.jdbc.driver.OracleDriver");
     Connection 

  con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
  Statement st=con.createStatement();

 ResultSet rs=st.executeQuery("select * from student where
 username='"+user+"' and 

 password='"+pass+"'");

  int count=0;
        while(rs.next())
       {
           count++;
       }

           if(count>0)
            {
             out.println("welcome "+user);
            }
           else
             {
               response.sendRedirect("studentlogin.jsp");
             } 

 }
   catch(Exception e) 
{  
 out.println(e); 
} 

 %>

    <a href="settings_std.jsp">Account Setting</a>

If the user is valid then he can see the option "Account setting". i.e.

 <%

    String username=request.getParameter("username");

      Connection con=null;

  try 

{

Class.forName("oracle.jdbc.driver.OracleDriver");

con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system",
 "manager");    

Statement
st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);


ResultSet rs=st.executeQuery("select * from from student where
 username='"+username+"'");


  if(rs.next())

 {

 %>

         <h3>Your Account Information</h3>

        <table>

<tr><td>Name:</td><td><input type="text" name="name" value="          <%=rs.getString("name")%>"></td></tr>


<tr><td>Degree:</td><td><input type="text" name="degree" value="<%=rs.getString("degree")%>"></td></tr>


<tr><td>Semester:</td><td><input type="text" name="semester" value="<%=rs.getString("semester")%>"></td></tr>


<tr><td>Branch</td><td><input type="text" name="branch" value="<%=rs.getString("branch")%>"></td></tr>



<tr><td>Contact No:</td><td><input type="text" name="mobile" value="<%=rs.getString("mobile")%>"></td></tr>


<tr><td>Email:</td><td><input type="text" name="email"
 value="<%=rs.getString("email")%>"></td></tr>


<tr><td>Password:</td><td><input type="text" name="password"  value="<%=rs.getString("password")%>"></td></tr>

</table>



 <%

   }

 con.close();
   }

 %>

Hope somebody knows this. Thank you.

4

1 回答 1

0

我已经解决了我的问题。要从数据库中获取值,我们可以使用 JSP 会话。

IE

<%
   String name = request.getParameter( "username" );
   session.setAttribute( "theName", name );
%>

在下一页中检索保存的用户名

ResultSet rs=st.executeQuery("select * from student where username='"+session.getAttribute("theName")+"'");

会话是与访问者关联的对象。可以将数据放入会话中并从中检索。

不管怎样,谢谢你们的尝试。

于 2013-04-20T06:20:40.177 回答