zoukankan      html  css  js  c++  java
  • 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页面了。。我真厉害

  • 相关阅读:
    <audio> 标签简介
    <sessionState>
    为 IIS 7.0 配置 <system.webServer>
    Litepal 数据库操作框架的使用 (火)
    Oracle Study之-AIX6.1构建Oracle 10gR2 RAC(4)
    【iOS开发-55】图片轮播案例:scrollView的分页、滚动栏、利用代理控制定时器和Page Control以及多线程问题
    小白学react之网页获取微信用户信息
    HTML5游戏实战(1):50行代码实现正面跑酷游戏
    浮动、定位
    Tomcat7.0源代码分析——启动与停止服务原理
  • 原文地址:https://www.cnblogs.com/cdl-sunshine/p/14159323.html
Copyright © 2011-2022 走看看