Hi all,
I've this following piece of code. It is a simple hands on exercise for my learning.
I retrieve data from a table called cat and what i would like to do is , go to the action page only if there is a record for that username and password.
Also i get an error while trying to use textbox names or id's inside java tags of JSP. Is there a way to access those elements.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.io.*,javax.servlet.ServletConfig,javax.servlet.ServletException,javax.servlet.http.HttpServlet,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Employee Login Page</title>
</head>
<body>
<form method = "POST" action = "http://localhost:8080/EmployeeSite/FetchEmployee">
User Name <input type = text name = UName id = UName/><br /><br />
Password <input type = password name = Pswd id = Pswd /><br /><br />
<button type = Submit>Submit </button>
<button type = Submit>Cancel </button>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:unisys");
String s1="select * from Cat where cid='"+Pswd+"' and cname ='"+UName+"'";
Statement st=cn.createStatement();
ResultSet rs= st.executeQuery(s1);
if(rs.next())
{
//validates it since there is a record.
}
else
{
//no record found.
}
}
catch(Exception e)
{
e.printStackTrace();
}%>
</form>
</body>
</html>