编程语言
首页 > 编程语言> > JavaWeb——课程管理系统(1)jsp界面---18.11.29

JavaWeb——课程管理系统(1)jsp界面---18.11.29

作者:互联网

add.jsp

<%@page import="com.jaovo.msg.Util.ValidateUtil"%>
<%@page import="com.jaovo.msg.Util.UserException"%>
<%@page import="com.jaovo.msg.dao.UserDaoImpl"%>
<%@page import="com.jaovo.msg.model.User"%>
<%@ 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>
<%
 //接收客户端传递过来的参数
 String name = request.getParameter("name");
 String time = request.getParameter("time");
 String jieci =request.getParameter("jieci");
 String college =request.getParameter("college");
 String tid =request.getParameter("tid");
 String tname =request.getParameter("tname");
 String number =request.getParameter("number");
 boolean validate = ValidateUtil.validateNull(request, new String[]{"name","time","jieci","college","tid","tname","number"});
 if(!validate){
%>
 <jsp:forward page="addInput.jsp"></jsp:forward>
<%
 }
 User user = new User();
 user.setName(name);
 user.setTime(time);
 user.setJieci(jieci);
 user.setCollege(college);
 user.setTid(tid);
 user.setTname(tname);
 user.setNumber(number);
 UserDaoImpl userDao = new UserDaoImpl();
 try{
 userDao.add(user);
 //重定向
 response.sendRedirect("index.jsp");//跳转
%>  
 
<%
 }catch(UserException e){
%>
 <h2 style="color:red ; font-size:50px">发生错误 : <%=e.getMessage() %></h2>
 <%
 }
 %>
</html>   addInput.jsp   <%@page import="com.jaovo.msg.Util.ValidateUtil"%>
<%@page import="java.util.Map"%>
<%@ 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>
 <title>用户添加页面</title>
</head>
<body>
<%--  <%Map<String,String> errorMsg = (Map<String,String>)request.getAttribute("errorMsg"); --%>
<%--  %> --%>
 
 <form action="add.jsp" method="get">
  <table align="center" border="1" width="500">
   <tr>
    <td>课程名称 : </td>
    <td>
     <input type="text" name="name" />
     <%
//       if(errorMsg != null){
//        if(errorMsg.get("name") != null){
//         out.println( errorMsg.get("name"));
//        }
//       }
      
     %>
     <%=ValidateUtil.showError(request, "name") %>
    </td>
   </tr>
    <tr>
       <td>上课时间:</td>
       <td>
        <input type="text" name="time" />
        <%
//       if(errorMsg != null){
//        if(errorMsg.get("time") != null){
//         out.println( errorMsg.get("time"));
//        }
//       }
        
     %>
     <%=ValidateUtil.showError(request, "time") %>
       </td>
      </tr>
      <tr>
       <td>课程节次:</td>
       <td>
        <input type="text" name="jieci" />
        <%
//       if(errorMsg != null){
//        if(errorMsg.get("jieci") != null){
//         out.println( errorMsg.get("jieci"));
//        }
//       }
        
     %>
     <%=ValidateUtil.showError(request, "jieci") %>
       </td>
      </tr>
      <tr>
       <td>所属学院:</td>
       <td>
        <input type="text" name="college" />
        <%
//       if(errorMsg != null){
//        if(errorMsg.get("college") != null){
//         out.println( errorMsg.get("college"));
//        }
//       }
        
     %>
     <%=ValidateUtil.showError(request, "college") %>
       </td>
      </tr>
      <tr>
       <td>教师工号:</td>
       <td>
        <input type="text" name="tid" />
        <%
//       if(errorMsg != null){
//        if(errorMsg.get("tid") != null){
//         out.println( errorMsg.get("tid"));
//        }
//       }
        
     %>
     <%=ValidateUtil.showError(request, "tid") %>
       </td>
      </tr>
      <tr>
       <td>教师姓名:</td>
       <td>
        <input type="text" name="tname" />
        <%
//       if(errorMsg != null){
//        if(errorMsg.get("tname") != null){
//         out.println( errorMsg.get("tname"));
//        }
//       }
        
     %>
     <%=ValidateUtil.showError(request, "tname") %>
       </td>
      </tr>
      <tr>
       <td>限制人数:</td>
       <td>
        <input type="text" name="number" />
        <%
//       if(errorMsg != null){
//        if(errorMsg.get("number") != null){
//         out.println( errorMsg.get("number"));
//        }
//       }
        
     %>
     <%=ValidateUtil.showError(request, "number") %>
       </td>
      </tr>
      <tr align="center">
       <td colspan="2">
        <input type="submit" value="提交" />
        <input type="reset" value="重置" />
       </td>
      </tr>
  </table>
 </form>
</body>
</html>   delete.jsp   <%@page import="com.jaovo.msg.Util.DaoFactory"%>
<%@page import="com.jaovo.msg.dao.UserDaoImpl"%>
<%@ 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">
<%
 int id = Integer.parseInt(request.getParameter("id"));
 //工厂模式
 UserDaoImpl userDao = DaoFactory.getDaoImpl();
 userDao.delete(id);
 response.sendRedirect("./index.jsp");
%>   index.jsp   <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>首页</title>
<style>
 .a{
  font-size: 26px;
  margin-top: 20px;
 }
</style>
</head>
<body>
 <div align="center">
  <h1 style="color: red;">欢迎来到课程系统</h1>
  <div class="a">
   <a href="addInput.jsp">增</a>
  </div>
  <div class="a">
   <a href="list.jsp">删</a>
  </div>
  <div class="a">
   <a href="list.jsp">改</a>
  </div>
  <div class="a">
   <a href="list.jsp">查</a>
  </div>
  
 </div>
</body>
</html>   list.jsp   <%@page import="com.jaovo.msg.model.User"%>
<%@page import="java.util.List"%>
<%@page import="com.jaovo.msg.dao.UserDaoImpl"%>
<%@ 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">
<title>用户展示界面</title>
</head>
<%
 UserDaoImpl userDao = new UserDaoImpl();
 List<User> users = userDao.load();
%>
<body>
 <table align="center" border="1" width="500">
  <tr>
   <td>课程编号</td>
   <td>课程名称</td>
   <td>开课时间</td>
   <td>开课节次</td>
   <td>所属学院</td>
   <td>教师工号</td>
   <td>教师名称</td>
   <td>限制人数</td>
  </tr>
  <%
   for( User user : users ){
  %>
  <tr>
   <td> <%=user.getId() %></td>
   <td> <%=user.getName() %></td>
   <td> <%=user.getTime() %></td>
   <td> <%=user.getJieci() %></td>
   <td> <%=user.getCollege() %></td>
   <td> <%=user.getTid() %></td>
   <td> <%=user.getTname() %></td>
   <td> <%=user.getNumber() %></td>
   <td> <a href="delete.jsp?id=<%=user.getId() %>" >删除</a></td>
   <td> <a href="updateInput.jsp?id=<%=user.getId() %>" >修改</a></td>
   
  </tr>
  <%
   }
  
  %>
  
 </table>
</body>
</html>   update.jsp   <%@page import="com.jaovo.msg.model.User"%>
<%@page import="com.jaovo.msg.Util.DaoFactory"%>
<%@page import="com.jaovo.msg.dao.IUserDao"%>
<%@page import="com.jaovo.msg.Util.ValidateUtil"%>
<%@ 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">
<%
 //获取客户端传递过来的参数
 int id = Integer.parseInt(request.getParameter("id"));
 String time = request.getParameter("time");
 String jieci = request.getParameter("jieci");
 String college = request.getParameter("college");
 String tid = request.getParameter("tid");
 String tname = request.getParameter("tname");
 String number = request.getParameter("number");
 
 boolean validate = ValidateUtil.validateNull(request, new String[]{"age","major"});
 if(!validate){
%> 
 <jsp:forward page="updateInput.jsp"></jsp:forward> 
<%
 }
 IUserDao userDao = DaoFactory.getDaoImpl();
 User user = userDao.load(id);
 
 user.setTime(time);
 user.setJieci(jieci);
 user.setCollege(college);
 user.setTid(tid);
 user.setTname(tname);
 user.setNumber(number);
 
 userDao.update(user);
 
 response.sendRedirect("index.jsp");
%>   updateInput.jsp   <%@page import="com.jaovo.msg.Util.ValidateUtil"%>
<%@page import="com.jaovo.msg.model.User"%>
<%@page import="com.jaovo.msg.Util.DaoFactory"%>
<%@page import="com.jaovo.msg.dao.IUserDao"%>
<%@ 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>
<title>用户修改页面</title>
</head>
<body>
 <%
  //获取客户端传递过来的参数
  int id = Integer.parseInt(request.getParameter("id"));
  IUserDao userDao = DaoFactory.getDaoImpl();
  User user = userDao.load(id);
 %>
 <form action="update.jsp" method="get">
  <table align="center" border="1" width="500">
   <input type="hidden" name="id" value="<%=user.getId() %>" />
   <tr>
    <td>课程名称 : </td>
    <td>
     <input type="text" name="name" value="<%=user.getName() %>" />
     <%=ValidateUtil.showError(request, "name") %>
    </td>
   </tr>
    <tr>
       <td>开课时间:</td>
       <td>
        <input type="text" name="time" value="<%=user.getTime() %>" />
        <%=ValidateUtil.showError(request, "time") %>
       </td>
      <tr>
    <td>开课节次 : </td>
    <td>
     <input type="text" name="jieci" value="<%=user.getJieci() %>" />
     <%=ValidateUtil.showError(request, "jieci") %>
    </td>
   </tr>
   <tr>
    <td>所属学院 : </td>
    <td>
     <input type="text" name="college" value="<%=user.getCollege() %>" />
     <%=ValidateUtil.showError(request, "college") %>
    </td>
   </tr>
   <tr>
    <td>教师工号 : </td>
    <td>
     <input type="text" name="tid" value="<%=user.getTid() %>" />
     <%=ValidateUtil.showError(request, "tid") %>
    </td>
   </tr>
   <tr>
    <td>教师姓名 : </td>
    <td>
     <input type="text" name="tname" value="<%=user.getTname() %>" />
     <%=ValidateUtil.showError(request, "tname") %>
    </td>
   </tr>
   <tr>
    <td>限制人数 : </td>
    <td>
     <input type="text" name="number" value="<%=user.getNumber() %>" />
     <%=ValidateUtil.showError(request, "number") %>
    </td>
   </tr>
      <tr align="center">
       <td colspan="2">
        <input type="submit" value="提交" />
        <input type="reset" value="重置" />
       </td>
      </tr>
  </table>
 </form>
</body>
</html>    

标签:18.11,JavaWeb,get,errorMsg,request,29,getParameter,user,String
来源: https://www.cnblogs.com/mitang0-0/p/10308316.html