いつもお世話になっております。
行いたい事はDBへ登録してある暗証番号は認識し、未登録ははじく処理を行いたいです。
DBはSQL Serverです。
以下がHTML(暗証番号入力画面)です。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
@import url("style.css") ;
</style>
<script type="text/javascript">
function onBlur(text) {
text.style.backgroundColor = "#D7EEFF";<!--水色 -->
}
</script>
<!-- 数値の連結 -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(function(){
$('input[type=button]').click(function(){
if ($('#text').val().length < 4) {
$('#text').val($('#text').val() + $(this).val());
}
});
});
</script>
</head>
<body onkeydown="return false;">
<div id="Numtitle">暗証番号を入力してください。</div>
<form method ="post" action="BalanceInquiry2(DB).jsp">
<div id="title">暗証番号:<input type="text" id="text" name="pass" value=""onblur="onBlur(this)" tabindex="1" title="4桁の暗証番号を入力してください。" ></div><br>
<br><table>
<div>
<tr>
<td><input type="button" value="7" id="7" tabindex="2" class="num-button" ></td>
<td><input type="button" value="8" id="8" tabindex="3" class="num-button" ></td>
<td><input type="button" value="9" id="9" tabindex="4" class="num-button" ></td>
</tr>
<tr>
<td><input type="button" value="4" id="4" tabindex="5" class="num-button" ></td>
<td><input type="button" value="5" id="5" tabindex="6"class="num-button" ></td>
<td><input type="button" value="6" id="6" tabindex="7" class="num-button" ></td>
</tr>
<tr>
<td><input type="button" value="1" id="1" tabindex="8" class="num-button" ></td>
<td><input type="button" value="2" id="2" tabindex="9" class="num-button" ></td>
<td><input type="button" value="3" id="3" tabindex="10" class="num-button" ></td>
</tr>
<tr>
<td colspan="3"><input type="button" value="0" tabindex="11" name="zero"class="num-button"></td>
</tr>
</div>
</table>
</div>
<div id="menu">
<table border="1">
<tr>
<td width="33.3%;"><input type="submit" value="戻る" class="button" name="Back" tabindex="12"onclick="history.back()"></td>
<td width="33.3%;"><input type="reset" value="訂正" class="button" name="Correction" tabindex="13"></td>
<td width="33.3%;"><input type="submit" value="確認" class="button" name="Check" tabindex="14"></td>
<td width="33.3%;"><input type="submit" value="メインメニュー"class="button" name="Back" tabindex="15" onclick="location.href='Mainmenu.jsp'"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
-------------------------------------------------
以下がDBへ接続する側のコードです。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
</head>
<body>
<form methhod="post" action="BalanceInquiry3.jsp">
<!-- 変数宣言 -->
<%! String passward; %>
<!-- テキストボックスの値取得 -->
<%
String passward = request.getParameter("pass");
try {
//JDBCドライバの読み込み
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//データベースへの接続
conn = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;"
+ "databaseName=" + "xx" + ";",
"id", "passward");
String SqlCount = "select count(暗証番号)from xx where='"+passward+"'";
//SELECT文の条件指定
PreparedStatement pStmt1 = conn.preparedStatement(SqlCount);
//SELECTを実行し、結果表を取得
ResultSet Result = pStmt1.executeQuery();
Result.next();
int get = Result.getInt("count(暗証番号)");
if(get==1){
%>
<script type="text/javascript">
alert("ようこそ。");
location.href='BalanceInquiry3.jsp';
</script>
<% }%>
<%}else if(get==0){ %>
<script type="text/javascript">
alert("暗証番号は登録していません。");
location.href='BalanceInquiry2.jsp';
</script>
<%
} catch (SQLException e){
e.printStackTrace();
}catch (ClassNotFoundException e){
e.printStackTrace();
}finally{
//データベースの切断
if (conn != null){
try{
conn.close();
}catch (SQLException e) {
e.printStackTrace();
}
}
}
%>
</form>
</body>
</html>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。