Kunal Lakhani 0 Newbie Poster

I have a login page, which directs to Verification.jsp

Login.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">   
<html>   
  <body>   
  <form action="Verification.jsp" method="POST">   
    <fieldset>   
<a   rel="nofollow">FreeLancer? Sign up!</a> <br/>   
<input type="radio" name="r1" value="Admin" checked="checked"/>Admin<br/>   
<input type="radio" name="r1" value="Editors"/>Editor<br/>   
<input type="radio" name="r1" value="Staff"/>Journalist<br>   
<input type="radio" name="r1" value="Staff"/>Reporter<br/>   
<input type="radio" name="r1" value="Freelancers"/>Freelancer<br/>   
<br/>   
<br/>   
USERNAME : <input type="text" name="t1"/><br>   
  
PASSWORD : <input type="password" name="t2" />   
<p/><input type="submit" value="Login">   
<input type="reset">   
       
    </fieldset>   
    </form>   
  </body>   
</html>

EveryThing in Login.jsp and verification.jsp is working fine.

I am having a STAFF table, which contains data of JOURNALIST & REPORTER. So, to differentiate their ID, i have a column STYPE, which contains 'R' for Reporter, and 'J' for journalist.


So, when Reporters logs in, i need 'R' to be generated, so that i can provide STYPE in my Query.

How to do this.?
If i place An attribute 'Id' in radio buttons in Login.jsp, how can i get this Id when the radio button is selected??


Verification.jsp

<%@ page language='java' import='java.sql.*,java.lang.*' %>   
  
<%   
try {   
    String str="";   
    String user=request.getParameter("r1");   
    String username=request.getParameter("t1");   
    String password=request.getParameter("t2");   
           
    if(user=="Staff"){   
        str="Select * from " +user+ " where username='"+username+"' and password='"+password+"' and stype='"***"' "; //here i need Id of reporter/journalist based on login//   
    }   
    else  
    {   
    str="Select * from " +user+ " where username='"+username+"' and password='"+password+"'";   
    }   
       
       
    if(username.trim().length()!=0 && password.trim().length()!=0)   
    {   
        Class.forName("oracle.jdbc.driver.OracleDriver");   
        Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle","scott","tiger");   
        Statement st=conn.createStatement();   
        ResultSet rs=st.executeQuery(str);   
System.out.println(str);   
        int c=0;   
        if(rs.next())   
         {   
            c++;   
            session.setAttribute("user",user);   
            session.setAttribute("username",rs.getString("username"));   
         }   
        st.close();   
        conn.close();   
       
        if(c==0)    
        {   
            session.setAttribute("msg","INVALID USERNAME/PASSWORD");   
            response.sendRedirect("errorpage.jsp");   
        }   
        else {   
        response.sendRedirect("frame.jsp");   
        }   
    }   
    else {   
       
    session.setAttribute("msg","UserName/Password Not Entered...");   
    response.sendRedirect("errorpage.jsp");   
    }      
}   
catch(Exception e) {   
e.printStackTrace();   
}   
 %>

I Should not include Java code in jsp, But this is just a rough project. After this, i will be converting this project as per MVC architecture

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.