//今天晚上没事干,练练手,学学js的知识:判断input 里面的type=text 里面的内容是否为空.
//one.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test Call Value</title>
</head>
<script type="text/javascript" language="javascript">
function checkinput(){
var frm=document.getElementById("iform");
var input=frm.getElementsByTagName("input");
var textcount1=0;
var textcount2=0;
for(i=0;i<input.length;i++){
{
if(input[i].type=="text"){
textcount1++;
if(input[i].value==""||input[i].value=="0"){
textcount2++;
}
}
}
}
if(textcount1==textcount2){
alert("请选择您要预订的房间及数量");
}
}
function checkname(){
var name=document.getElementsByName("name").value;
if(name==""){
alert("姓名为空,请您认真填写");
}
}
checkreg=function(){
var _user=document.getElementById("iname");
var _clas=document.getElementById("iclas");
var _istuid=document.getElementById("istuid");
var _iterm=document.getElementById("iterm");
var _introduce=document.getElementById("iitroduce");
if(_user.value==""){
alert("请输入用户名称");
_user.focus();
return;
}
if(_clas.value==""){
alert("请输入班级,呵呵,朋友你错啦");
_clas.focus();
return;
}
if(_istuid.value==""){
alert("学号为空,请您认真填写");
_istuid.focus();
return;
}
if(_iterm.value==""){
alert("您的学期为空,请您认真填写");
_iterm.focus();
return;
}
if(_introduce.value==""){
alert("您的介绍为空,请认真填写,呵呵。朋友你错啦");
_introduce.focus();
return;
}
}
</script>
<body>
<form id="iform" name="tform" method="method" action="two.jsp">
姓名
<input id="iname" name="name" type="text" /><br/>
班级
<input id="iclas" name="clas" type="text" /><br/>
学号
<input id="istuid" name="stuid" type="text" /><br/>
学期
<input id="iterm" name="term" type="text" /><br/>
简介
<input id="iitroduce" name="introduce" type="text" /><br/>
<input type="submit" value="提交" onclick="checkreg();" /><br/>
</form>
</body>
</html>
//two.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.sql.*,java.util.*,java.text.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>处理数据</title>
</head>
<body>
<%
String name=request.getParameter("name");
String clas=request.getParameter("clas");
String stuid=request.getParameter("stuid");
String term=request.getParameter("term");
String introduce=request.getParameter("introduce");
Connection conn=null;
PreparedStatement ps=null;
int i=0;
try{
String url="jdbc:oracle:thin:@localhost:1521:orcl";
conn=DriverManager.getConnection(url,"zhang","zhang");
String sql="insert into call (name,class,stuid,term,introduce) values (?,?,?,?,?)";
ps=conn.prepareStatement(sql);
ps.setString(1,name);
ps.setString(2,clas);
ps.setString(3,stuid);
ps.setString(4,term);
ps.setString(5,introduce);
ps.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}finally{
if(ps!=null){
ps.close();
}
if(conn!=null){
conn.close();
}
}
out.println("//以下是从数据库里面读取出来的内容");
out.println("<br/>");
Connection connl=null;
PreparedStatement psl=null;
ResultSet rs=null;
try{
String url="jdbc:oracle:thin:@localhost:1521:orcl";
conn=DriverManager.getConnection(url,"zhang","zhang");
String sql="select * from call order by createtime desc";
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
out.println("id:"+rs.getString("id"));
out.println("-name:"+rs.getString("name"));
out.println("-class:"+rs.getString("class"));
out.println("-stuid:"+rs.getString("stuid"));
out.println("-term:"+rs.getString("term"));
out.println("-introduce:"+rs.getString("introduce"));
out.println("<br>");
out.println("<a href=\"three.jsp?id="+rs.getString("id")+"\">"+rs.getString(name)+"</a>");
out.println("<a href=\"\">"+88+"</a>" );
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs!=null){
rs.close();
}
if(psl!=null){
psl.close();
}
if(connl!=null){
connl.close();
}
}
%>
</body>
</html>
//three.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>跳转</title>
</head>
<body>
<%
String id=request.getParameter("id");
out.println("<a href=\"\">"+id+"<br/>");
%>
</body>
</html>