zoukankan      html  css  js  c++  java
  • 课程添加web

    12.17

    今天开始做一个小的web项目,计划两天写完,今天没有遇到问题,明天计划吧项目弄完。

    下面是今天的代码部分:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>增加学生对象页面</title>
    </head>
    <body>
    <form action="add1.jsp" method="post">
    <%
    Object result = request.getAttribute("result");//放置一个字符串,并取出
    if(result!=null && !"".equals(result)){

    %>
    <script type="text/javascript">
    alert("<%=request.getAttribute("result")%>");
    request.setAttribute("result", "");
    </script>
    <%} %>
    <table align="center">
    <tr>
    <td>课程名称:</td>
    <td>
    <input type="text" name="name">
    </td>
    </tr>
    <tr>
    <td>任课教师:</td>
    <td>
    <input type="text" name="people">
    </td>
    </tr>
    <tr>
    <td>上课地点:</td>
    <td>
    <input type="text" name="place">
    </td>
    </tr>
    <tr align="center">
    <td>
    <input type="submit" value="添加">
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="com.pp.dao"%>
    <%@ page import="com.pp.servlet"%>
    <%@ page import="com.pp.kecheng"%>
    <meta charset="UTF-8">
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <%
    String classname = request.getParameter("name");
    String classtea = request.getParameter("people");
    String classspace = request.getParameter("place");
    if(classtea.equals("王建民")||classtea.equals("刘丹")||classtea.equals("刘立嘉")||classtea.equals("王辉")||classtea.equals("杨子光"))
    {

    }
    else
    {
    request.setAttribute("result","请输入在职老师");
    %>
    <jsp:forward page="add.jsp"></jsp:forward>
    <%
    }
    kecheng course=new kecheng();
    course.setName(classname);
    course.setPeople(classtea);
    course.setPlace(classspace);
    dao.insert(course);
    request.setAttribute("result","课程添加成功");
    %>
    <jsp:forward page="add.jsp"></jsp:forward>
    <%

    %>


    <body>
    </body>
    </html>

    package com.pp;
    import java.sql.*;
    import java.util.ArrayList;
    import java.util.List;
    public class dao {
    public static void insert(kecheng L) {
    String sql="insert into kecheng(name,people,place) values(?,?,?)";
    Connection con;
    try {
    con = DBUtil.getConnection();
    PreparedStatement pa=con.prepareStatement(sql);
    pa.setString(1,L.getName());
    pa.setString(2,L.getPeople());
    pa.setString(3,L.getPlace());

    pa.execute();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    }

  • 相关阅读:
    如何对已上架的宝贝进行调整不被降权?
    报错ERR_CONNECTION_REFUSED,如何解决(原创)
    ***在Linux环境下mysql的root密码忘记解决方法(三种)-推荐第三种
    微信获取用户基本信息,头像是一张“暂时无法查看”的图?
    Linux中zip压缩和unzip解压缩命令详解
    Android必知必会-App 常用图标尺寸规范汇总
    国外主机海外主机测评总结
    美国主机BlueHost vs HostEase
    cPanel中添加设置附加域(Addon domain)
    香港新世界机房和电讯盈科机房,沙田机房,葵芳机房哪数据中心一个好?服务器托管
  • 原文地址:https://www.cnblogs.com/092e/p/14169593.html
Copyright © 2011-2022 走看看