6、addrom.jsp
录入房间信息,然后存入数据库。
<jsp:useBean id="myconnect" scope="session" class="student.DBConnect"></jsp:useBean>
<%
if (session.getAttribute("login") == null)
out.print("<script>alert('请先登录!');window.location.href='login.jsp'</script>");
String buildingid = request.getParameter("buildingid");
String roomid = request.getParameter("roomid");
String sex = request.getParameter("sex");
String amount = request.getParameter("amount");
String expense = request.getParameter("expense");
if (buildingid != null && roomid != null) {
String sqlText = "select*from room where building='" + buildingid + "'and room='" + roomid + "'";
ResultSet rsaddroom;
rsaddroom = myconnect.DBQuery(sqlText);
if (rsaddroom != null && rsaddroom.next())
request.setAttribute("message", "该栋楼的房间已经登记!");
else {
String inserttext = "";
inserttext = "insert into room values(null,'" + buildingid + "','" + roomid + "','" + sex + "','"
+ amount + "','" + expense + "');";
myconnect.DBUpdate(inserttext);
request.setAttribute("message", "新数据添加成功!");
}
}
%>
<!-- 判断输入是否为空 -->
<script type="text/javascript">
function datacheck() {
if (form.buildingid.value == "") {
alert("请输入楼号!");
document.form.buildingid.focus();
} else {
if (form.roomid.value == "") {
alert("请输入房号!");
document.form.roomid.focus();
} else {
if (form.sex.value == "") {
alert("请选择入住性别!");
document.form.sex.focus();
} else {
if (form.amount.value == "") {
alert("请输入可住人数!");
//document.form.amount.focus();
} else {
if (form.expense.value == "") {
alert("请输入住宿费用!");
// document.form.expense.focus();
} else {
form.submit();
}
}
}
}
}
}
</script>
<pre name="code" class="html"><body bgcolor="#CFE3CA" text="#004080">
<p align="center">${message}</p>
<form id="form" name="form" method="post" action="addroom.jsp">
<table width="40%" border="1" align="center" bordercolor="#004080"
bgcolor="#CCCCCC" id="house">
<tr>
<td height="40" colspan="2">
<div align="center">
<p>
<strong><font size="4">录入房间信息</font></strong>
</p>
</div>
</td>
</tr>
<tr>
<td width="43%" height="43">
<div align="center">楼号</div>
</td>
<td width="57%" height="43"><input name="buildingid"
type="text" size="20" /></td>
</tr>
<tr>
<td height="50" width="43%">
<div align="center">房号</div>
</td>
<td width="57%" height="50"><input name="roomid" type="text"
size="20" /></td>
</tr>
<tr>
<td height="48" width="43%">
<div align="center">入住性别</div>
</td>
<td height="48" width="57%"><select name="sex">
<option value="">请选择</option>
<option value="男">男</option>
<option value="女">女</option>
</select></td>
</tr>
<tr>
<td height="59" width="43%">
<div align="center">可住人数</div>
</td>
<td height="59" width="57%"><input name="amount" type="text"
size="20" /></td>
</tr>
<tr>
<td height="53" width="43%">
<div align="center">住宿费用</div>
</td>
<td height="53" width="57%"><input name="expense" type="text"
size="13" /></td>
</tr>
<tr>
<td colspan="2" height="40">
<div align="center">
<input type="button" name="Submit1" value="确定"
οnclick="datacheck()" /> <input type="reset" name="Submit2"
value="取消" />
</div>
</td>
</tr>
</table>
</form>
</body>
7、addstudent.jsp
录入学生信息,然后存入数据库。
<%
if(session.getAttribute("login")==null)
out.print("<script>alert('请先登录!');window.location.href='login.jsp'</script>");
%>
<%
String studentid=request.getParameter("studentid");
String roomid=request.getParameter("roomid");
String sex=request.getParameter("sex");
String department=request.getParameter("department");
String buildingid=request.getParameter("buildingid");
String name=request.getParameter("name");
String sqlText="select*from student where id='"+studentid+"'";
String inserttext="";
ResultSet rsaddstudent;
rsaddstudent=myconnect.DBQuery(sqlText);
rsaddstudent.next();
if(( rsaddstudent.next())==true)
response.sendRedirect("update_error.jsp");
else{
inserttext="insert into student values('"+studentid+"','"+name+"','"+sex+"','"+department+"','"+buildingid+"','"+roomid+"');";
myconnect.DBUpdate(inserttext);
request.setAttribute("message", "新数据添加成功!");
}
%>
<!-- 判断输入是否为空 -->
<script language="javascript">
function datacheck(){
if(form.studentid.value==""){
alert('请输入学号!');
document.form.studentid.focus();
}
else{
if(form.name.value==""){
alert('请输入姓名!');
document.form.name.focus();
}
else{
if(form.sex.value==""){
alert('请选择性别!');
document.form.sex.focus();
}
else{
if(form.department.value==""){
alert('请选择院系!');
document.form.department.focus();
}
else{
if(form.buildingid.value==""){
alert('请输入楼号!');
document.form.buildingid.focus();
}
else{
if(form.roomid.value==""){
alert('请输入房号!');
document.form.roomid.focus();
}else{
form.submit();
}
}
}
}
}
}
}
</script>
<body bgcolor="#CFE3CA" text="#004080">
<p align="center">
${message}
</p>
<form id="form" name="form1" method="post" action="addstudent.jsp">
<table width="35%" border="1" align="center" bordercolor="#004080" bgcolor="#CCCCCC">
<tr>
<td colspan="2" height="47">
<div align="center"><strong>录入学生信息</strong></div>
</td>
</tr>
<tr>
<td width="35%" height="40">
<div align="center">学号</div>
</td>
<td width="70%" height="40">
<input name="studentid" type="text" size="20" />
</td>
</tr>
<tr>
<td height="41">
<div align="center">姓名</div>
</td>
<td height="41">
<input name="name" type="text" size="20" />
</td>
</tr>
<tr>
<td height="34">
<div align="center">性别</div>
</td>
<td height="34">
<select name="sex">
<option value="">请选择</option>
<option value="男">男</option>
<option value="女">女</option>
</select>
</td>
</tr>
<tr>
<td height="39">
<div align="center">院系</div>
</td>
<td height="39">
<select name="department">
<option value="0" selected>请选择</option>
<option value="计算机系">计算机系</option>
<option value="化工学院">化工学院</option>
<option value="外国语学院">外国语学院</option>
<option value="文学院">文学院</option>
</select>
</td>
</tr>
<tr>
<td height="46">
<div align="center">楼号</div>
</td>
<td height="46">
<input name="buildingid" type="text" size="20" />
</td>
</tr>
<tr>
<td height="40">
<div align="center">房号</div>
</td>
<td height="40">
<input name="roomid" type="text" size="20" />
</td>
</tr>
<tr>
<td colspan="2" height="40">
<div align="center">
<input name="Submit1" type="button" οnclick="datacheck()" value="确定" />
<input name="Submit2" type="reset" value="取消" />
</div>
</td>
</tr>
</table>
</form>
</body>