How to display a different page in JSP if user email address not in database?

santana9

Banned
Jan 19, 2003
154
0
0
Hi, this is for an unsubscribe page in which a user specifies their email address in a text box and that entry is checked in the database. If they are found the "future_promo" field is changed from a "Y" to a "N" and the "opt_out_date" field is populated w/ the systemdate. The user is then redirected to a thankyou page. The problem I am running into is how do I redirect the user to another page if their name isnt in the database. So I want to have two pages one with a thank you message and one with an I'm sorry we are unable to located your name in our database. Here is my code for the jsp page:

<%@ page import="java.lang.*, java.util.*, java.io.*, javax.servlet.*, javax.servlet.http.*, java.sql.*" %>
<%

//loading the JDCB driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

// Defining the connection URL
String host = "NCSPRD01.RAR.NCSUS.JNJ.COM";
String dbName = "CPC1";
int port = 1523;
String oracleURL = "jdbc:eek:racle:thin:mad:" + host + ":" + port + ":" + dbName;

//Establish the connection
String username = "WWIM";
String password = "WWIM12";

String email = request.getParameter("txtEmail").trim();

Connection cn=null;
cn = DriverManager.getConnection(oracleURL, username, password);
// Query to get email value from db

Statement statement = cn.createStatement();
String UpdateKySampling = "Update kyTest Set Future_Promo = 'N', opt_out_date = sysdate where email = " +
"("+"'"+email+"')";
String commit = "commit";

//Execute the Update
statement.executeUpdate(UpdateKySampling);
statement.executeUpdate(commit);
statement.close();

cn.close();

%>
<html>
<head>
<title>Welcome to K-Y.com!!</title>
<link href="/css/ky.css" rel="stylesheet" type="text/css">
</head>
<body>
<!--INCLUDE HEADER-->
<jsp:include page="/include/navigation/index.html" flush="true" />
<p align="center"><b>
<span class="ProdJelly">You have been successfully unsubscribed.
Click here to go back to:<p align="center"><a href="http://www.ky.com">www.ky.com</a></b></p></span>
</body>
</html>

Thanks in advance.
 

joshg

Golden Member
Jul 3, 2001
1,359
0
0
Well I've never worked heavily in JSP but just to let you know how the design of something could work, you would need to get a recordset for

"SELECT email FROM kyTest WHERE email = " +"("+"'"+email+"')";

And then if your Recordset is EOF (there are no records returned) then they are not in the DB, so forward them to the "sorry" page, otherwise, run your UPDATE statement and give them the "thank you" page. Actually, you could just have two different result prints that way you just have one "page" that handles the action, and it says "thanks" if their record existed and you updated it, but it says "sorry" if they weren't in the DB...