java基础练习项目--比较乱,仅供自己作为笔记
SelectCourseTeacherServlet.java
package com.aaa.servlet;import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aaa.service.ICourseServerDAO;
import com.aaa.service.impl.CourseServerDaoImpl;
import com.alibaba.fastjson.JSON;
@WebServlet("/SCTS")
public class SelectCourseTeacherServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
//得到课程编号,查询教课老师
String classnum=request.getParameter("classnum");
String classstatus=request.getParameter("classstatus");
System.out.println("传递递过来的课程编号"+classnum+"传递过来的课程性质"+classstatus);
//调用CourseServerDaoImpl创建对象,连接数据库
ICourseServerDAO icsd= new CourseServerDaoImpl();
List<Map<String,Object>> list= icsd.selectcourseteacher(classnum);
System.out.println("查询的教师名字结果集"+list);
String res=JSON.toJSONString(list);
response.setContentType("text/html;charset=utf-8");
response.getWriter().write(res);
}
}
SelectCourseBySelectedServlet.java
package com.aaa.servlet;import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aaa.entity.Course;
import com.aaa.entity.Teacher;
import com.aaa.service.ICourseServerDAO;
import com.aaa.service.impl.CourseServerDaoImpl;
import com.alibaba.fastjson.JSON;
@WebServlet("/SCBSS")
public class SelectCourseBySelectedServlet extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("欢迎来到...............SCDSS....................");
request.setCharacterEncoding("utf-8");
//实例化对象
Course course=new Course();
Teacher teacher=new Teacher();
//获得selectinfo.jsp的传值
String classnum=request.getParameter("classnum");
String classstatus=request.getParameter("classstatus");
String teacherjobnum=request.getParameter("teacherjobnum");
//向实体类写入信息
// int classid=Integer.parseInt(classnum);
// int tjobnum=Integer.parseInt(teacherjobnum);
// course.setId(classid);
// course.setStatus(classstatus);
// teacher.setJobnum(tjobnum);
System.out.println(classnum+"课程名称 "+classstatus+"课程性质 "+teacherjobnum+"任课老师");
ICourseServerDAO icsd=new CourseServerDaoImpl();
List<Map<String,Object>> list=icsd.selectcoursebytea(classnum, classstatus, teacherjobnum);
System.out.println(list);
//如果查出来结果就返回结果集,如果没有查出来结果,就返回错误信息给用户
if(list.size()>0&&list!=null) {
String s=JSON.toJSONString(list);
response.setContentType("text/html;charset=utf-8");
response.getWriter().write(s);
}else {
Map<String,Object> map=new HashMap<String,Object>();
//返回错误代码
map.put("code", "000000");
String map1=JSON.toJSONString(map);
response.setContentType("text/html;charset=utf-8");
response.getWriter().write(map1);
}
}
}
SelectCourseInfoServlet.java
package com.aaa.servlet;import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import com.aaa.entity.Course;
import com.aaa.entity.PageBean;
import com.aaa.entity.Student;
import com.aaa.entity.Teacher;
import com.aaa.service.ICourseServerDAO;
import com.aaa.service.impl.CourseServerDaoImpl;
@WebServlet("/SCIS")
public class SelectCourseInfoServlet extends HttpServlet {
//查询选课管理页面中下拉列框中的信息
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("欢迎bbbbbbbbbbbbbbbbbbbbbbbbbb");
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=uft-8");
Course course=new Course();
Teacher teacher=new Teacher();
Student student=new Student();
//分页查询数据库
String pageC=request.getParameter("pageCode");
System.out.println("当前页数"+pageC);
int pageCode=1;//第一次登录默认第一页
if(pageC!=null&&pageC.trim().length()>0) {
pageCode=Integer.parseInt(pageC);
}
int pageSize=5;
//调用courseServerDaoImpl获得类对象连接数据库
ICourseServerDAO icsd=new CourseServerDaoImpl();
PageBean bypage=icsd.findByPage(pageCode, pageSize,course,teacher);
//下拉列表中的值
//调用方法进行查询课程表中课程名和id
List<Map<String,Object>> list=icsd.selectcourseinfo();
//调用方法查询课程表中的课程性质
List<Map<String,Object>> list2=icsd.selectcoursestatusinfo();
System.out.println(list);
System.out.println(list2);
List<Object> listall=new ArrayList<Object>();
listall.add(list);
listall.add(list2);
request.setAttribute("list", listall);
request.setAttribute("bypage", bypage);
request.getRequestDispatcher("/selectclass/selectinfo.jsp").forward(request,response);
}
}
Selectinfo.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no,maximum-scalable=1.0">
<title>Insert title here</title>
<link rel="stylesheet" href="<%=basePath%>/css/bootstrap.min.css">
<script type="text/javascript" src="<%=basePath%>/css/jquery-2.1.3.js"></script>
<style>
.t1:hover{
color:#0D73CB;
}
</style>
<script type="text/javascript">
function ajax(){
var classnum=$("#classname option:selected").val();
var classstatus=$("#classstatus option:selected").val();
//alert(classnum+" "+classstatus);
$("#teachername option:gt(0)").remove();
$.ajax({
type:"post",
url:"<c:url value=\'/SCTS\'/>",
data:{"classnum":classnum,"classstatus":classstatus},
dataType:"json",
success:function(backresult,ststus,xmlHttpServlet){
//alert(backresult);
$.each(backresult,function(i,res){
$("#teachername").append("<option value="+res.jobnum+">"+res.name+"</option>");
})
},
error:function (XMlHttpServlet,status,errorThrown){
alert("执行错误");
}
});
}
</script>
<script type="text/javascript">
function selectby(){
document.getElementById("divboot").style.visibility="hidden";
//alert("欢迎查询");
var classnum=$("#classname option:selected").val();//课程代码
var classstatus=$("#classstatus option:selected").val();//课程性质
var teacherjobnum=$("#teachername option:selected").val();//教师编号
$.ajax({
type:"post",
url:"<c:url value=\'/SCBSS\'/>",
data:{"classnum":classnum,"classstatus":classstatus,"teacherjobnum":teacherjobnum},
dataType:"json",
success:function(backresult,ststus,xmlHttpServlet){
//alert(backresult);
if(backresult.code=="000000"){
alert("请核对课程信息后,进行重新选择");
}else{
var no="人数已满";
var yes="选课";
//得到原页面中table的行数
var alltr=$("#tbody").find("tr").length;
//alert("共有"+alltr);
//将原页面中的tr删除
for(var i=0;i<alltr;i++){
document.getElementById("tbody").deleteRow(0);
}
$.each(backresult,function(i,res){
if(res.fixed<res.num){
$("#tbody").append("<tr><td>"+res.code+"</td><td>"+res.cname+"</td><td>"+res.tname+"</td><td>"+res.status+"</td><td>"+res.credit+"</td><td>"+res.num+"</td><td>"+res.fixed+"</td><td><a href=\'javascript:void(0)\' onclick=\'xuanke(" + res.code + "," + res.jobnum + ")\'>"+yes+"</a></td></tr>");
}else{
$("#tbody").append("<tr><td>"+res.code+"</td><td>"+res.cname+"</td><td>"+res.tname+"</td><td>"+res.status+"</td><td>"+res.credit+"</td><td>"+res.num+"</td><td>"+res.fixed+"</td><td>"+no+"</td></tr>");
}
})
}
},
error:function(XMlHttpServlet,status,errorThrown){
alert("执行错误");
}
})
}
</script>
</head>
<body>
<h2>选课管理</h2>
课程名称<select id="classname" class="btn btn-default">
<option value="">---请选择课程名称---</option>
<c:forEach items="${list[0]}" var="lis">
<option value="${lis.id}">${lis.name}</option>
</c:forEach>
</select>
课程性质<select id="classstatus" class="btn btn-default" onchange="ajax()">
<option value="">---课程性质---</option>
<c:forEach items="${list[1]}" var="lis1">
<option value="${lis1.status}">${lis1.status}</option>
</c:forEach>
</select>
任课老师<select id="teachername" class="btn btn-default">
<option value="0">---任课老师---</option>
</select>
<!--<button type="button" name="selected" class="btn btn-primary btn-sm" onclick="selectby()">查询</button> -->
<input type="submit" name="selected" class="btn btn-primary btn-sm" onclick="selectby()" value="查询"/>
<table class="table table-striped"> <!-- 设置表格斑马线 -->
<thead> <!-- 下面都能改 -->
<tr>
<th>课程编码</th>
<th>课程名称</th>
<th>任课老师</th>
<th>课程性质</th>
<th>学分</th>
<th>容量</th>
<th>已选人数</th>
<th>操作</th>
</tr>
</thead>
<tbody id="tbody">
<c:forEach items="${bypage.queryLists}" var="course">
<tr class="t1">
<td>${course.code}</td>
<td>${course.cname}</td>
<td>${course.tname}</td>
<td>${course.status}</td>
<td>${course.credit}</td>
<td>${course.num}</td>
<td>${course.fixed}</td>
<c:choose>
<c:when test="${course.num>course.fixed}">
<td><a href="<c:url value="/ISCS?c_code=${course.code}&t_jobnum=${course.jobnum}"/>">选课</a></td>
</c:when>
<c:otherwise>
<td>人数已满</td>
</c:otherwise>
</c:choose>
</tr>
</c:forEach>
<c:choose>
<c:when test="${success==000000}">
<!-- <p style="color:red; margin-left:1600px;">选课成功,请等待审核</p> -->
<script>
alert("选课成功,请等待审核");
</script>
</c:when>
<c:when test="${success==111111}">
<!--<p style="color:red; margin-left:1600px;">已经选过该课程,请重新选择</p> -->
<script>
alert("已经选过该课程,请重新选择");
</script>
</c:when>
</c:choose>
</tbody>
</table>
<div id="divboot" style="visibility:none">
<ul class="pagination"> <!-- disabled不可用 active变色 -->
<li class="disabled"><a href="#">第${bypage.pageCode}页</a></li>
<li class="disabled"><a href="#">共${bypage.totalPage}页</a></li>
<li ><a href="<c:url value="/SCIS?pageCode=1"/>">首页</a></li>
<li >
<c:if test="${bypage.pageCode>1}">
<a href="<c:url value=\'/SCIS?pageCode=${bypage.pageCode-1}\'/>">上一页</a>
</c:if>
</li>
<li >
<c:if test="${bypage.pageCode<bypage.totalPage}">
<a href="<c:url value="/SCIS?pageCode=${bypage.pageCode+1}"/>">下一页</a>
</c:if>
</li>
<li ><a href="<c:url value="/SCIS?pageCode=${bypage.totalPage}"/>">尾页</a></li>
</ul>
</div>
</body>
<script>
function xuanke( code, jobnum){
var code1=code;
var jobnum1=jobnum;
//alert(code1);
//alert(jobnum1);
window.location.href="/courseProject/ISCS?c_code="+code1+"&t_jobnum="+jobnum1+"";
}
</script>
</html>
selectresult.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no,maximum-scalable=1.0">
<title>Insert title here</title>
<link rel="stylesheet" href="<%=basePath%>/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/css/jquery-2.1.3.js"></script>
<style>
.t1:hover{
color:#0D73CB;
}
</style>
</head>
<body>
<h2>选课状态展示</h2>
<form action="<c:url value="/SRS"/>" method="get">
课程名称<select id="classcode" name="classcode" class="btn btn-default">
<option value="0">-------课程名称------</option>
<c:forEach items="${resultlist[0]}" var="list1">
<option value="${list1.code}">${list1.name}</option>
</c:forEach>
</select>
课程性质<select id="classstatus" name="classstatus" class="btn btn-default">
<option value="">------课程性质------</option>
<c:forEach items="${resultlist[1]}" var="list2">
<option value="${list2.status}">${list2.status}</option>
</c:forEach>
</select>
任课老师<select id="teacherjobnum" name="teacherjobnum" class="btn btn-default">
<option value="">-----教师姓名-----</option>
<c:forEach items="${resultlist[2]}" var="list3">
<option value="${list3.jobnum}">${list3.name}</option>
</c:forEach>
</select>
<button type="submit" class="btn btn-primary btn-sm">查询</button>
</form>
<table class="table table-striped"> <!-- 设置表格斑马线 -->
<thead> <!-- 下面都能改 -->
<tr>
<th>课程编码</th>
<th>课程名称</th>
<th>任课老师</th>
<th>课程性质</th>
<th>学分</th>
<th>容量</th>
<th>已选人数</th>
<th>状态</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<c:forEach items="${resultlist[3].queryLists}" var="list4">
<tr class="t1">
<td>${list4.code}</td>
<td>${list4.cname}</td>
<td>${list4.tname}</td>
<td>${list4.status}</td>
<td>${list4.credit}</td>
<td>${list4.num}</td>
<td>${list4.fixed}</td>
<c:if test="${list4.state==0}">
<td>待审核</td>
</c:if>
<c:if test="${list4.state==1}">
<td style="color:blue">通过</td>
</c:if>
<c:if test="${list4.state==2}">
<td style="color:red">未通过</td>
</c:if>
<td>${list4.comment}</td>
</tr>
</c:forEach>
</tbody>
</table>
<ul class="pagination"> <!-- disabled不可用 active变色 -->
<li class="disabled"><a href="#">第${resultlist[3].pageCode}页</a></li>
<li class="disabled"><a href="#">共${resultlist[3].totalPage}页</a></li>
<li ><a href="<c:url value="/SRS?pageCode=1"/>">首页</a></li>
<li >
<c:if test="${resultlist[3].pageCode>1}">
<a href="<c:url value="/SRS?pageCode=${resultlist[3].pageCode-1}"/>">上一页</a>
</c:if>
</li>
<li >
<c:if test="${resultlist[3].pageCode<resultlist[3].totalPage}">
<a href="<c:url value="/SRS?pageCode=${resultlist[3].pageCode+1}"/>">下一页</a>
</c:if>
</li>
<li ><a href="<c:url value="/SRS?pageCode=${resultlist[3].totalPage}"/>">尾页</a></li>
</ul>
</body>
</html>
以上是 java基础练习项目--比较乱,仅供自己作为笔记 的全部内容, 来源链接: utcz.com/z/394966.html