CodeToad Forums » Java » developing a bookselling system using jsp: need help in fixing database error
|
|
|
my code as follows: debug.jsp - used for validations
<?xml version="1.0" encoding ="UTF-8"?>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%-- \WEB-INF\jsp\cw\debug.jsp --%>
<%-- debug include file --%>
<c:if test ="${sessionScope.sessDebug == 'true'}">
<table border="1">
<c:forEach var="item" items="${cookie}">
<tr>
<td>inbound cookies</td>
<td>${item.key}</td>
<td>${item.value.value}</td> <%--note the .value.value--%>
</tr>
</c:forEach>
<c:forEach var="item" items="${param}">
<tr>
<td>inbound parameter</td>
<td>${item.key}</td>
<td>${item.value}</td> <%--note the .value--%>
</tr>
</c:forEach>
<c:forEach var="item" items="${requestScope}">
<tr>
<td>request scope object</td>
<td>${item.key}</td>
<td>${item.value}</td>
</tr>
</c:forEach>
<c:forEach var="item" items="${sessionScope}">
<tr>
<td>session scope object</td>
<td>${item.key}</td>
<td>${item.value}</td>
</tr>
</c:forEach>
</table>
</c:if>
router.jsp - forward success failure pages
<?xml version="1.0" encoding ="iso-8859-1"?>
<%-- /WEB-INF/jsp/cwjsps/router.jsp --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%-- setup session if one does not exist --%>
<%@ page session="true" %>
<%-- set up debug variable --%>
<c:set var="sessDebug" scope="session" value="true"/>
<%-- get pathinfo information from the request --%>
<%-- this defines which use case has been requested --%>
<c:set var="pgePathInfo" scope="page" value="${pageContext.request.pathInfo}" />
<%-- uc02 : Login --%>
<c:if test="${pageScope.pgePathInfo =='/home'}" >
<jsp:forward page="/WEB_INF/jsp/cwjsps/home.html"/>
</c:if>
<c:if test="${pageScope.pgePathInfo =='/login'}" >
<jsp:forward page="/WEB_INF/jsp/cwjsps/prologin.html"/>
</c:if>
<%-- uc01 : View Details Of Books For Sale --%>
<c:if test="${pageScope.pgePathInfo =='/viewbooksforsale'}" >
<jsp:forward page="/WEB_INF/jsp/cwjsps/probooksforsale.html"/>
</c:if>
<%-- uc01 : process User registration--%>
<c:if test="${pageScope.pgePathInfo =='/userregistration'}" >
<jsp:forward page="/WEB_INF/jsp/cwjsps/proregistration.html"/>
</c:if>
<%-- uc01 : debug --%>
<c:if test="${pageScope.pgePathInfo =='/debug'}" >
<jsp:forward page="/WEB_INF/jsp/cwjsps/debug.html"/>
</c:if>
<%-- uc01 : view Traders Own View --%>
<c:if test="${pageScope.pgePathInfo =='/Traderhomepage'}" >
<jsp:forward page="/WEB_INF/jsp/cwjsps/Traderhomepage.html"/>
</c:if>
<%-- otherwise --%>
<jsp:forward page="/WEB_INF/jsp/cwjsps/home.html"/>
userregistration.jsp - jsp user view page
<?xml version="1.0" encoding ="UTF-8"?>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Registeres USers Login Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body>
<%--debugging code--%>
<%@ include file="/forum/debug.html" %>
<table width="1049" cellpadding="5" align="center">
<tr>
<td width="2378"><div align="center">
<h2 align="center"> User Registration</h2>
<p>
<c:url var="HmePgeURL" value="/cw/router/home" scope="page"/>
<a href="${HmePgeURL}">Home</a> <c:url var='BSPgeURL' value='/cw/router/login' scope='page'/>
<a href="${BSPgeURL}">Buy or Sell</a>
</p>
</div></td>
</tr>
</table>
<p align="center"> </p>
<p>This website is only open to members of the De MontFort University.
You will need a current @learner.dmu.ac.uk e-mail address in order to register.</p>
<p> If you've already registered for one site you do not need to register again </p>
<c:url value="/cw/router/userregistration" var="UregPgeURL" scope="page"/>
<form name="frmregister" method="post" action="${UregPgeURL}">
<div>
<table width="726" height="285" border="0" align="left" cellpadding="2" cellspacing="0">
<tr>
<td width="157" align="right" >Name:</td>
<td width="561" > <input name="txtname" type="text" value="${param.txtname}"/> </td>
</tr>
<c:if test="${!empty requestScope.reqInvalidUserName}">
<c:out value="${requestScope.reqInvalidUserName}"/>
</c:if>
<tr>
<td width="157" align="right" >Department</td>
<td align="left" >
<select name="txtdepartment" value="${param.txtdepartment}" >
<option></option>
<option value="Faculty of Art and Design">Faculty of Art and Design</option>
<option value="Faculty of Business and Law">Faculty of Business and Law</option>
<option value="Faculty of Computing Sciences and Engineering">Faculty of Computing Sciences and Engineering</option>
<option value="Faculty of Health and Life Sciences">Faculty of Health and Life Sciences</option>
<option value="Faculty of Humanities">Faculty of Humanities</option>
</select>
</td>
</tr>
<tr>
<td align="right" >Programme</td>
<td ><input type="text" name="txtprogramme" value="${param.txtprogramme}" />
(eg: BIS,SE) </td>
</tr>
<tr>
<td align="right" >Telephone Number: </td>
<td ><input name="txtphonenum" type="text" value="${param.txtphonenum}" /></td>
</tr>
<tr>
<td align="right" >Date Of Birth: </td>
<td ><input name="txtday" type="text" size="15" value="${param.txtdob}" />(of format YYYY-MM-DD)</td>
</tr>
<tr>
<td align="right" >Username</td>
<td align="left" >
<input name="txtuserid" type="text" size="15" value="${param.txtuserid}" />
(eg. p07269027 from P07269027@learner.dmu.ac.uk)</td>
<c:if test="${!empty requestScope.reqInvalidUserId}">
<c:out value="${requestScope.reqInvalidUserId}"/>
</c:if>
</tr>
<tr>
<td align="right" >Password</td>
<td align="left" >
<input name="txtpassword" type="password" size="15" value="${param.txtpassword}" />
</td></tr>
<c:if test="${!empty requestScope.reqInvalidPassword}">
<c:out value="${requestScope.reqInvalidPassword}"/>
</c:if>
<tr>
<td align="right" >Confirm Password </td>
<td align="left" >
<input name="txtpasswordconf" type="password" size="15" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="frmsubmit" type="submit" value="Register User" />
<input type="reset" name="Reset" value="Reset" />
</td>
</tr>
</table>
<c:if test="${!empty requestScope.reqQueryErrorMessage}">
<c:out value="${requestScope.reqQueryErrorMessage}"/>
</c:if>
<c:if test="${!empty requestScope.reqInvalidUpdate}">
<c:out value="${requestScope.reqInvalidUpdate}"/>
</c:if>
</div>
</form>
</body>
</html>
proregistration.jsp - jsp process page
<?xml version="1.0" encoding ="UTF-8"?>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%-- \WEB-INF\jsp\cwjsps\probooksforsale.jsp --%>
<%-- Probookforsale --%>
<%-- skip field validation and provide blankpage if first time in --%>
<c:if test="${empty sessionScope.mc07kpkDataSource}">
<sql:setDataSource
var="mc07kpkdbDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/mc07kpkdb"
scope="session"
user="mc07kpk_web"
password="beGin+35"
/>
</c:if>
<c:if test="${empty param.frmsubmit}">
<c:set var="reqOutcome" scope="request" value=" "/>
<jsp:forward page="/WEB_INF/jsp/cwjsps/userregistration.html"/> <%-- initial request --%>
</c:if>
<%-- validate txtname --%>
<c:if test="${empty param.txtname}">
<c:set var="reqInvalidUserName" scope="request" value= "User Name Cannot Be Empty"/>
</c:if>
<%-- validate txtuserid --%>
<c:if test="${empty param.txtuserid}">
<c:set var="reqInvalidUserId" scope="request" value= "User ID Cannot Be Empty"/>
</c:if>
<%-- validate txtpassword--%>
<c:if test="${empty param.txtpassword}">
<c:set var="reqInvalidPassword" scope="request" value= "Password Cannot Be Empty"/>
</c:if>
<%-- if userid invalid or username invalid --%>
<%-- redisplay form with originl typed-in data and with errors marked --%>
<c:if test="${empty param.txtname or empty param.txtuserid}">
<c:set var="reqOutcome" scope="request" value= "failure" />
<jsp:forward page="/WEB_INF/jsp/cwjsps/userregistration.html"/> <%-- failure --%>
</c:if>
<c:catch var="pgeQueryError">
<sql:update var="pgeRowCount" scope="page" >
<%-- insert details to trader table --%>
INSERT INTO trader (dbTraderName,dbTraderDepartment,dbTraderProgramme,dbTraderPhoneNum ,dbTraderDOB,dbTraderPNumber,dbTraderPwd)
VALUES (?,?,?,?,?,?,?)
<sql:param value="${param.txtname}"/>
<sql:param value="${param.txtdepartment}"/>
<sql:param value="${param.txtprogramme}"/>
<sql:param value="${param.txtphonenum}"/>
<sql:param value="${param.txtdob}"/>
<sql:param value="${param.txtuserid}"/>
<sql:param value="${param.txtpassword}"/>
</sql:update>
</c:catch>
<%-- check For query Error --%>
<c:if test="${not empty pgeQueryError}">
<c:choose>
<%-- check duplicate record --%>
<c:when test="${pgeQueryError.rootCause.errorCode =='1062'}">
<c:set var="reqQueryErrorMessage" scope="request" value="User already Registered - Duplicate Record" />
<jsp:forward page="/WEB_INF/jsp/cwjsps/login.html"/>
</c:when>
<c:otherwise>
<%-- database error --%>
<c:set var="reqQueryErrorMessage" scope="request" value="Database Error" />
<jsp:forward page="/WEB_INF/jsp/cwjsps/userregistration.html"/>
</c:otherwise>
</c:choose>
<c:set var="reqOutcome" scope="request" value="failure" />
<jsp:forward page="/WEB_INF/jsp/cwjsps/userregistration.html"/>
</c:if>
<%-- check For no rows returned --%>
<c:if test="${pgeRowCount !=1}">
<c:set var="reqInvalidUpdate" scope="request" value="*** rowCount not = 1"/>
<c:set var="reqOutcome" scope="request" value="failure"/>
<jsp:forward page="/WEB_INF/jsp/cwjsps/userregistration.html"/> <%-- failure --%>
</c:if>
<%-- Otherwise --%>
<%-- Outcome is success --%>
<c:if test="${pgeRowCount ==1}">
<c:set var="reqOutcome" scope="request" value="success" />
<jsp:forward page="/WEB_INF/jsp/cwjsps/login.html"/> <%-- success --%>
</c:if>
|
|
|
Beautiful blog with great informational content. Mostly certifications related and fixing database error related topics are really very good. HP0-J29 braindumps, CISM dumps and 1Y0-264 dumps are also good topics. Thanks for this great sharing.
|
|
|
|
|
|
|
|