表:
create table STUDENT
(
ID NUMBER,
NAME VARCHAR2(100),
PASSWORD VARCHAR2(100),
JIGUAN VARCHAR2(200),
DEPARTMENT VARCHAR2(100),
SEX VARCHAR2(100),
TEL VARCHAR2(100),
EMAIL VARCHAR2(200),
MARK NUMBER
)
tablespace SYSTEM
pctfree 10
pctused 40
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
代码:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;public class StudentSvlt extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String stu_id =req.getParameter("id");
int success = 0;
String action = action = req.getParameter("action");
student stu = null;
String message="";
if ("new".equalsIgnoreCase(action)) {
stu = doNew(req,res);
sendBean(req, res, stu, "/getStudent.jsp");
}
if ("update".equalsIgnoreCase(action)) {
try{
stu = doUpdate(req,res, stu_id);
sendBean(req,res,stu,"/getStudent.jsp");
}
catch(SQLException e){}
}
if ("delete".equalsIgnoreCase(action)) {
try{
success = doDelete(stu_id);
}
catch(SQLException e){}
if (success != 1) {
doError(req, res, "StudentSvlt: Delete unsuccessful. Rows affected: " + success);
} else {
res.sendRedirect("/getStudent.jsp");
}
}
}
public student doNew(HttpServletRequest req,HttpServletResponse res )
throws ServletException,IOException{
student stu= new student();
String stu_id=req.getParameter("id");
String name=new String(req.getParameter("name").getBytes("ISO8859_1"));
String password= req.getParameter("password");
String dep=new String (req.getParameter("dep").getBytes("ISO8859_1"));
String sex = new String(req.getParameter("sex").getBytes("ISO8859_1"));
String jiguan = new String(req.getParameter("jiguan").getBytes("ISO8859_1"));
if(isTrue(req,res,stu_id,name,password) && hasLogin(req,res,stu_id)){
stu.setId(stu_id);
stu.setName(name);
stu.setPassword(password);
stu.setDep(dep);
stu.setSex(sex);
stu.setJiguan(jiguan);
stu.addStudent(); }
return stu;
} public student doUpdate(HttpServletRequest req,HttpServletResponse res , String id)
throws ServletException,IOException,SQLException {
student stu = new student();
String name=new String(req.getParameter("name").getBytes("ISO8859_1"));
String password = req.getParameter("password");
String dep = new String(req.getParameter("dep").getBytes("ISO8859_1"));
String sex = new String(req.getParameter("sex").getBytes("ISO8859_1"));
String jiguan = new String(req.getParameter("jiguan").getBytes("ISO8859_1"));
if(isTrue(req,res,id,name,password)){
stu.setId(id);
stu.setName(name);
stu.setPassword(password);
stu.setDep(dep);
stu.setSex(sex);
stu.setJiguan(jiguan);
stu.updateStudent();}
return stu;
} public int doDelete(String id) throws SQLException {
int num=0;
student stu=new student();
num=stu.deleteStudent(id);
return num;
}
public void sendBean(HttpServletRequest req, HttpServletResponse res,
student stu, String target)
throws ServletException, IOException {
req.setAttribute("stu", stu);
RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
rd.forward(req, res);
}
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}
public boolean hasLogin(HttpServletRequest req, HttpServletResponse res,String id)
throws ServletException, IOException{
boolean f=true;
String message="对不起,该学生号已经被注册过了!";
student stu= new student();
f= stu.hasLogin(id);
if(f==false){
doError(req,res,message);
}
return f;
}
public boolean isTrue(HttpServletRequest req, HttpServletResponse res,
String id,String name,String password)
throws ServletException, IOException {
boolean f=true;
String message ="";
if(id==null || id.equals("")) {
f=false;
message="错误,学生号不能为空!";
doError(req,res,message); }
if(name==null || name.equals("")) {
f=false;
message="学生姓名不能为空,请重新填写!";
doError(req,res,message); }
if(password==null || password.equals("")) {
f=false;
message="密码不能为空,请重新填写!";
doError(req,res,message); } return f;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException { doGet(req, res); }
}
create table STUDENT
(
ID NUMBER,
NAME VARCHAR2(100),
PASSWORD VARCHAR2(100),
JIGUAN VARCHAR2(200),
DEPARTMENT VARCHAR2(100),
SEX VARCHAR2(100),
TEL VARCHAR2(100),
EMAIL VARCHAR2(200),
MARK NUMBER
)
tablespace SYSTEM
pctfree 10
pctused 40
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
代码:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;public class StudentSvlt extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String stu_id =req.getParameter("id");
int success = 0;
String action = action = req.getParameter("action");
student stu = null;
String message="";
if ("new".equalsIgnoreCase(action)) {
stu = doNew(req,res);
sendBean(req, res, stu, "/getStudent.jsp");
}
if ("update".equalsIgnoreCase(action)) {
try{
stu = doUpdate(req,res, stu_id);
sendBean(req,res,stu,"/getStudent.jsp");
}
catch(SQLException e){}
}
if ("delete".equalsIgnoreCase(action)) {
try{
success = doDelete(stu_id);
}
catch(SQLException e){}
if (success != 1) {
doError(req, res, "StudentSvlt: Delete unsuccessful. Rows affected: " + success);
} else {
res.sendRedirect("/getStudent.jsp");
}
}
}
public student doNew(HttpServletRequest req,HttpServletResponse res )
throws ServletException,IOException{
student stu= new student();
String stu_id=req.getParameter("id");
String name=new String(req.getParameter("name").getBytes("ISO8859_1"));
String password= req.getParameter("password");
String dep=new String (req.getParameter("dep").getBytes("ISO8859_1"));
String sex = new String(req.getParameter("sex").getBytes("ISO8859_1"));
String jiguan = new String(req.getParameter("jiguan").getBytes("ISO8859_1"));
if(isTrue(req,res,stu_id,name,password) && hasLogin(req,res,stu_id)){
stu.setId(stu_id);
stu.setName(name);
stu.setPassword(password);
stu.setDep(dep);
stu.setSex(sex);
stu.setJiguan(jiguan);
stu.addStudent(); }
return stu;
} public student doUpdate(HttpServletRequest req,HttpServletResponse res , String id)
throws ServletException,IOException,SQLException {
student stu = new student();
String name=new String(req.getParameter("name").getBytes("ISO8859_1"));
String password = req.getParameter("password");
String dep = new String(req.getParameter("dep").getBytes("ISO8859_1"));
String sex = new String(req.getParameter("sex").getBytes("ISO8859_1"));
String jiguan = new String(req.getParameter("jiguan").getBytes("ISO8859_1"));
if(isTrue(req,res,id,name,password)){
stu.setId(id);
stu.setName(name);
stu.setPassword(password);
stu.setDep(dep);
stu.setSex(sex);
stu.setJiguan(jiguan);
stu.updateStudent();}
return stu;
} public int doDelete(String id) throws SQLException {
int num=0;
student stu=new student();
num=stu.deleteStudent(id);
return num;
}
public void sendBean(HttpServletRequest req, HttpServletResponse res,
student stu, String target)
throws ServletException, IOException {
req.setAttribute("stu", stu);
RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
rd.forward(req, res);
}
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}
public boolean hasLogin(HttpServletRequest req, HttpServletResponse res,String id)
throws ServletException, IOException{
boolean f=true;
String message="对不起,该学生号已经被注册过了!";
student stu= new student();
f= stu.hasLogin(id);
if(f==false){
doError(req,res,message);
}
return f;
}
public boolean isTrue(HttpServletRequest req, HttpServletResponse res,
String id,String name,String password)
throws ServletException, IOException {
boolean f=true;
String message ="";
if(id==null || id.equals("")) {
f=false;
message="错误,学生号不能为空!";
doError(req,res,message); }
if(name==null || name.equals("")) {
f=false;
message="学生姓名不能为空,请重新填写!";
doError(req,res,message); }
if(password==null || password.equals("")) {
f=false;
message="密码不能为空,请重新填写!";
doError(req,res,message); } return f;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException { doGet(req, res); }
}
解决方案 »
- ResultSet rs=stmt.executeQuery(sql)获取不到数据
- powerDesigner的用法
- shell在java ee应用中一般有什么应用 ?
- 本人有一定编程基础,现在需要学习java web开发,希望各位有经验的介绍一本书,最好能详细介绍mvc或struts2或其他的,要有实例程序,能让我自己模仿做一个来入门。这样我自己就能深入学习了。谢谢
- rmi找不到stub
- 使用URLDecoder.decode 报URLDecoder: Illegal hex characters in escape (%) pattern -
- 新人求指点,如何点击删除选中的链接,急~~(SpringMVC)
- JAVA与/。NET的选择
- 用java编写 http协议 的 post 和 get 方法(请赐教!)
- hibernate cache问题
- Struts1.1的配置
- 问一问题
从表结构来看,只有id和是number型,而你插入更新都没用到,那么问题估计就出现在id上if(name==null || name.equals("")) //这里只判断id是否为空,并没有判断id是否是数字类型,如果页面上输入了非数字的字符,那么数据库插入更新就会出现这个错了