当前位置 : 主页 > 编程语言 > java >

课程添加web

来源:互联网 收集:自由互联 发布时间:2022-06-23
12.17 今天开始做一个小的web项目,计划两天写完,今天没有遇到问题,明天计划吧项目弄完。 下面是今天的代码部分: %@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8

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();
}
}

}

 


上一篇:选课小web最终版
下一篇:没有了
网友评论