<%@ page language="java" import="java.util.*,com.db.*,java.sql.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme() "://" request.getServerName() ":" request.getServerPort() path "/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'AddStudentData.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <% request.setCharacterEncoding("UTF-8"); String studentNumber=request.getParameter("studentNumber"); String studentName=request.getParameter("studentName"); String studentSex=request.getParameter("studentSex"); int studentAge=Integer.parseInt(request.getParameter("studentAge")); int studentWeight=Integer.parseInt(request.getParameter("studentWeight")); Connection conn=null; PreparedStatement ps=null; try{ conn=DBConnection.getConn(); ps=conn.prepareStatement("insert into Student values(?,?,?,?,?)"); ps.setString(1,studentNumber); ps.setString(2,studentName); ps.setString(3,studentSex); ps.setInt(4,studentAge); ps.setInt(5,studentWeight); int i=ps.executeUpdate(); if(i>0) response.sendRedirect("StuAdmin.jsp"); }catch(Exception e){ e.printStackTrace(); }finally{ DBConnection.close(null,ps,conn); } %> </body></html>
评论