/    Sign up×
Community /Pin to ProfileBookmark

Setting cookies variables in jsp

<%@page contentType=”text/html”%>
<%@ page import = “java.io.*” %>
<%@ page import = “java.util.*
” %>
<%@ page import = “javax.servlet.*” %>
<%@ page import = “javax.servlet.http.*
” %>
<%@ page import = “java.sql.*” %>
<%@ page import=”java.lang.*
” %>
<%@ page session=”true” %>
<%@ page import=”java.io.IOException.*” %>
<%@ page import=”java.io.PrintWriter.*
” %>
<%@ page import=”javax.servlet.Servlet.*” %>
<%@ page import=”javax.servlet.ServletException.*
” %>
<%@ page import=”javax.servlet.http.Cookie.*” %>
<%@ page import = “javax.servlet.http.HttpServlet.*
” %>
<%@ page import=”javax.HttpServletRequest.*” %>
<%@ page import=”javax.HttpServletResponse.*
” %>
<html>
<head>
<title> </title>
</head>
<body>

<%

String Name, Password, formName, formPassword; int ID; long time;
try {
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

Connection C = DriverManager.getConnection(“jdbc:odbc:REX”);

Statement Stmt = C.createStatement();

String queryString;

ResultSet rs;

boolean check=false;

if(request.getParameter(“select”).equals(“Trader”))
{//if Trader Option
queryString=”SELECT TraderID,Name,Password FROM Trader”;
rs = Stmt.executeQuery(queryString);

while (rs.next())
{
Name=rs.getString(“Name”);
Password=rs.getString(“Password”);
formName=request.getParameter(“username”);
formPassword=request.getParameter(“password”);
//out.println(“<br>Username:”+Name+” vs “+formName+”<br>Password:”+Password+” vs “+formPassword);

if (formName.equals(Name) && formPassword.equals(Password))
{

check=true;
// session.setAttribute(“update_trader”,”0″);
response.sendRedirect(“Trader/TraderPage.htm”);
break;
}
}
rs.close();

}//if Trader Option

if(request.getParameter(“select”).equals(“Dealer”))
{//if Dealer Option
queryString=”SELECT DealerID,Name,Password FROM Dealer”;
rs = Stmt.executeQuery(queryString);

while (rs.next())
{
Name=rs.getString(“Name”);
Password=rs.getString(“Password”);
formName=request.getParameter(“username”);
formPassword=request.getParameter(“password”);
//out.println(“<br>Username:”+Name+” vs “+formName+”<br>Password:”+Password+” vs “+formPassword);

if (formName.equals(Name) && formPassword.equals(Password))
{
Cookie userCookie = new Cookie(“user”, “uid1234”);
Cookie.setMaxAge(24 * 60 * 60);
response.addCookie(userCookie);
ID=rs.getInt(“DealerID”);
String sID=””+ID;
check=true;
session.setAttribute(“Name”,Name);
session.setAttribute(“DealerID”,sID);
response.sendRedirect(“Dealer/dealerpage.htm”);
break;
}
}
rs.close();

}//if Dealer Option

if(request.getParameter(“select”).equals(“Administrator”))
{//if Administrator Option
queryString=”SELECT AdministratorID,Name,Password FROM Administrator”;
rs = Stmt.executeQuery(queryString);

while (rs.next())
{
Name=rs.getString(“Name”);
Password=rs.getString(“Password”);
formName=request.getParameter(“username”);
formPassword=request.getParameter(“password”);
//out.println(“<br>Username:”+Name+” vs “+formName+”<br>Password:”+Password+” vs “+formPassword);

if (formName.equals(Name) && formPassword.equals(Password))
{
check=true;
// session.setAttribute(“update_dealer”,”0″);
response.sendRedirect(“Admin/adminpage.htm”);
break;
}
}
rs.close();

}//if Administrator Option

if (check==false)
{
response.sendRedirect(“All_WrongPassword.html”);
}

Stmt.close();
C.close();
}
catch (ClassNotFoundException e1) {
// JDBC driver class not found, print error message to the console
System.out.println(e1.toString());
}
catch (SQLException e2) {
// Exception when executing java.sql related commands, print error message to the console
System.out.println(e2.toString());
}
catch (Exception e3) {
// other unexpected exception, print error message to the console
System.out.println(e3.toString());
}

%>
</body>
</html>

</body>
</html>

I set a cookie for dealer after verifying the username and pw. However if i wish to assign the userid (domain ) and dealerID (generated from the access table) to the cookie instead of typing in manually like what i’m doing now, how could i go about doing it?

2nd problem i’m facing is that i can’t verify login name and PW from the trader and administrator domain. Only the dealer is unaffected. I’m sure my tables are done correctly and the fields are correct.

Here is my source for the login page

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>

<body>
<img src=”Xara/banner%20copy.jpg” width=”1000″ height=”90″>

<script menumaker>document.write(‘<scr’+’ipt src=”xaramenu.js”>’+'</scr’+’ipt>’);document.write(‘<scr’+’ipt src=”Xara/dimpletab.js”>’+'</scr’+’ipt>’);/*img src=”Xara/DimpleTab.gif” moduleid=”forex (project)DimpleTab_off.xws”*/</script>
<table width=”97%” border=”0″ align=”center” cellpadding=”2″ cellspacing=”4″>
<tr valign=”top”>
<td width=”144″ rowspan=”2″ align=”center” bgcolor=”#FFFFCC”> <p align=”left”><font color=”#0033FF”><strong>
<a href=”Overview.htm” style=”text-decoration: none”>4Rex Overview</a></strong></font></p>
<p align=”left”><font color=”#0033FF”><strong> <a href=”Gettingstarted.htm” style=”text-decoration: none”>Getting
Started</a></strong></font></p>
<p align=”left”><font color=”#0033FF”><strong><a href=”Account%20registration.htm” style=”text-decoration: none”>Open
an Account</a></strong></font></p>
<p align=”left”><font color=”#0033FF”><strong><a href=”Contact%20us.htm” style=”text-decoration: none”>Contact
Us</a></strong></font></p>
<p align=”left”><font color=”#0033FF”><strong> </strong></font><font color=”#0033FF”><strong>Login</strong></font></p>

<form name=”form1″ method=”post” action=”passcheck.jsp”>
<div align=”left”> <font color=”#0033FF”>
<input type=”text” name=”username” size=”20″>
<strong>User Name:</strong></font></div>
<div align=”left”>
<p><font color=”#0033FF”>
<input type=”text” name=”password” size=”20″>
<strong>Password:</strong></font></p>
<p><strong><font color=”#0033FF”>
<select name=”select”>
<option>Dealer</option>
<option>Trader</option>
<option>Adminstrator</option>
</select>
</font></strong></p>
<p><strong><font color=”#0033FF”>
<input type=”submit” name=”Submit” value=”Submit”>
</font></strong></p>
</div>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
<td width=”833″ height=”212″ bgcolor=”#CCCCCC”> <p>News Headlines</p>
<p>Completion of 1st login page ^_^ </p>
<p>Still sucks I’ll try and see what i can do.<a href=”#”></a></p>
<p>&nbsp;</p></td>

</tr>
<tr>
<td bgcolor=”#CCCCCC”> <p>Community </p>
<p>4 members</p>
<p>&nbsp;</p></td>
</tr>
</table>
<p>&nbsp;</p>
<p> <font color=”#0000FF”><a href=”Index.htm” style=”text-decoration: none”>Home Page</a> |
<a href=”Account%20registration.htm” style=”text-decoration: none”>Open an Account</a> |
<a href=”Contact%20us.htm” style=”text-decoration: none”>Contact 4Rex</a> |
<a href=”Riskdisclaimer.htm” style=”text-decoration: none”>Risk Disclaimer</a></font></p>
<p><u>_______________________________________________________________________________________________________________________________</u></p>
</body>
</html>

Someone please help thanks. T_T

[b]Moderators Note[/b]
Being moved to Java Forums.

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@JPnycSep 26.2004 — Topic was moved to the appropriate forum.
×

Success!

Help @tenerazza spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...