Java
T
point
Home
Core Java
Servlet
JSP
Struts2
Mail API
Hibernate
Spring
Android
Design Pattern
Projects
Interview Q
View All Questions
Ask New Question
How can we apply session on name ?
By:
chopra***
On:
Thu Nov 19 14:28:12 IST 2015
0
0
0
0
Hi Guys,
I have a login form in jsp in which the user enter email id and password to login and proceed further.
Now i want to apply session on name so that i can get its value on the next page but it is not displaying the name on the next page.
May be the email id is used in the login form.Kindly let me know how i can resolve this and if it is possible to fetch the name on email id bases.
For reference check the code below :
String name=request.getParameter("name");
String email=request.getParameter("email");
String cat=request.getParameter("cat");
String pwd=request.getParameter("pwd");
if(cat.equals("Voter"))
{
try
{
Connection con1=Connect.getConnection();
Statement stmt =con1.createStatement();
String query=("select * from voter where email='"+email+"' and pwd='" + pwd + "'");
ResultSet rs=stmt.executeQuery(query);
if(rs.next())
{
session.setAttribute("name",name);
response.sendRedirect("account.jsp");
}
else
{
out.println("error1");
}
}
catch(Exception e)
{
out.print("Hey..Exception is here"+e);
}
}
else if(cat.equals("Admin"))
{
try
{
Connection con1=Connect.getConnection();
Statement stmt =con1.createStatement();
String query=("select * from admin where email='"+email+"' and pwd='" + pwd + "'");
ResultSet rs=stmt.executeQuery(query);
if(rs.next())
{
out.println("hello2");
}
else
{
out.println("error2");
}
}
catch(Exception e)
{
out.print("Hey..Exception is here"+e);
}
}
else if(cat.equals("Inspector"))
{
try
{
Connection con1=Connect.getConnection();
Statement stmt =con1.createStatement();
String query=("select * from inspector where email='"+email+"' and pwd='" + pwd + "'");
ResultSet rs=stmt.executeQuery(query);
if(rs.next())
{
out.println("hello3");
}
else
{
out.println("error3");
}
}
catch(Exception e)
{
out.print("Hey..Exception is here"+e);
}
}
else if(cat.equals("Nominee"))
{
try
{
Connection con1=Connect.getConnection();
Statement stmt =con1.createStatement();
String query=("select * from nominee where email='"+email+"' and pwd='" + pwd + "'");
ResultSet rs=stmt.executeQuery(query);
if(rs.next())
{
out.println("hello4");
}
else
{
out.println("error4");
}
}
catch(Exception e)
{
out.print("Hey..Exception is here"+e);
}
}
else
{
out.print("Kindly select the correct category");
}
0
session.setAttribute("name",name);
correct this
session.setAttribute("name",rs.getString("name"));
0
By:
[email protected]
On:
Fri Nov 20 13:11:02 IST 2015
0
0
0
0
Are You Satisfied :
0Yes
0No