使用JSP对数据库进行增删改查.docVIP

  • 34
  • 0
  • 约1.14万字
  • 约 11页
  • 2017-05-19 发布于重庆
  • 举报
使用JSP对数据库进行增删改查

使用JSP对数据库进行增删改查 注意红体字! 首先,打开sql server 2005,输入用户名(我用的登录名是panpan)密码(我设置的是123)。 先建个表student, Create table stu( id number(30) , name varchar(50) , age number(30), sex varchar(30), major varchar(50) ); 打开MyEclipse,新建一个新项目,让后将index.jsp删除,然后在webRoot文件中新建以下 几个jsp文件。 index.jsp %@ page language=java import=java.util.* pageEncoding=GB2312% % String path = request.getContextPath(); String basePath = request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/; % html head base href=%=basePath% title输入学生信息界面/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 script type=text/javascript function validate() { var id=document.forms[0].id.value; var name=document.forms[0].name.value; var age=document.forms[0].age.value; var major=document.forms[0].major.value; if(id=0){ alert(学号不能为空,请输入学号!); return false; } else if(name.length=0){ alert(姓名不能为空,请输入姓名!); return false; } else if(age=0){ alert(请输入合法年龄!); return false; } else if(major.length=0){ alert(专业不能为空,请输入所学专业!); return false; } else{ return true; } } /script /head body br center h2学生信息输入/h2hr form action=insert.jsp method=post id=form onSubmit= validate() h4 学号:input type=text name=id class={required:true}/inputbr/h4 h4 姓名:input type=text name=name/inputbr/h4 h4 年龄:input type=text name=age/inputbr/h4 h4 性别:input type=radio name=sex value=男男 input type=radio name=sex value=女女br/h4 h4 专业:input type=text name=major/inputbr/h4 input type=submit value=提交/ /form a href=layout.jsp查看已输入信息/a /center /body /html insert.jsp %@ page language=java import=java.util.* pageEncoding=gb2312% %@ page import=java.sql.*% % String path = request.getContextPat

文档评论(0)

1亿VIP精品文档

相关文档