• 课程添加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();
    }
    }

    }

  • 相关阅读:
    05mybatis配置方式简单入门
    04mybatis配置文件lombok组件使用
    03mybatis-注解方式简单入门实例
    01-02 ssm框架简介
    jsp实现文件上传
    新增的语义化标签
    html5与html4的区别
    面向对象总结
    html语法
    购物车总结
  • 原文地址:https://www.cnblogs.com/092e/p/14169593.html
Copyright © 2020-2023  润新知