1 2 3 4

10.21

经过在网上对数据库和前段web界面的知识的学习,我终于知道怎么和数据库交互了

来,看代码,先看一下昨天选课的那个界面吧

<%@ 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>
    /*<style type="text/css">
        body{
            background: #FFFF00;
            align-items: center;
            text-align: center;
        }
    </style>*/
    
</head>

<body>
<body background="123.jpg"></body>
<%
String s=(String)request.getAttribute("Error");
if("".equals(s)||s==null)
{
    s="";
}
%>
<%=s %>
<form action="LoginInput.jsp" method="get">
        <table align="center" border="1">
<tr>
<td colspan="2">
课程名称
 <input type="text" name="name"/>
</td>
</tr>
<tr>
   <td colspan="2">
    任课教师
 <input type="text" name="teacher"/>
   </td>
  </tr>
  <tr>
   <td colspan="2">
    上课地点
 <input type="text" name="place"/>
   </td>
  </tr>
 
  <tr>
  <td align="center" colspan="2">
   <input type="submit" value="保存"/></td>
  </tr>
  </table>
  </form>
</body>
</html>

再看看和后台数据库交互的界面

 

<%@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>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
         int i=0;
         boolean flag=true;
         boolean flag1=true;
         String s[]={"王建民","刘丹","刘立嘉","杨子光","王辉"};
         String s1[]={"基教","一教","二教","三教"};
         String name=request.getParameter("name");
         String teacher=request.getParameter("teacher");
         String place=request.getParameter("place");
        while(i<s.length)
         {
        if(!s[i].equals(teacher))
     {
      flag=false;
     }
        else
            {
            flag=true;
            break;
            }
      i++;
     }%>
     <%
     if(!flag)
     {
         request.setAttribute("Error", "老师不对");
     
     %>
     <jsp:forward page="Login.jsp"></jsp:forward>
       <% 
     }
     i=0;
     String s3=place.substring(0,2);
 
     while(flag==true&&i<s1.length)
     {
        
    if(!s1[i].equals(s3))
         {
             flag1=false;
          }
         else
        {
        flag1=true;
        break;
        }
          i++;
       }
     if(!flag1)
     {
         request.setAttribute("Error", "教室不对");
     
     %>
     <jsp:forward page="Login.jsp"></jsp:forward>
       <% 
     }
        UserDaoImpl userdao=new UserDaoImpl();
         User user=new User();
         user.setName(name);
         user.setTeacher(teacher);
         user.setPlace(place);
         userdao.add(user);
         System.out.println(teacher);
%>

<<jsp:forward page="Login.jsp"></jsp:forward>

哈哈哈哈!!!我居然写出来一个web页面了。。我真厉害

posted @ 2020-10-21 22:15  小陈的太阳  阅读(72)  评论(0编辑  收藏  举报