第一個JSP界面 untitled.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page import="java.io.*,java.uitl.*" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<%
String checkInside=(String) session.getValue("insideUser");
if(checkInside==null)
{
response.sendRedirect("untitled1.jsp");
}
String name=(String) session.getValue("name");
%>
<script language="javascript">
function moveButtonClick(type){
if(document.formx.user_id.value==""){
alert("沒有記錄可供操作");
return false;
}
else
{
document.formx.action="manage_deal.jsp?moveButton=" + type;
document.formx.submit();
}
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<body>
<form name="fromx" method="post" >
<input type="hidden" name="user_id" value="<%= name %>" />
<input type="text" name="user_name" size="14" value="<%= name %>" /> </td>
<input name="moveButton" type="button" value="下一條"size="4" onClick="moveButtonClick('next')" />
</form>
</body>
</html>
第二個JSP界面untitled1.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String username="admin";
String userpassword="123456";
String sConnStr="jdbc:sqlserver://localhost:1433;DatabaseName=hysjdb";
Connection conn=null;
conn=DriverManager.getConnection(sConnStr,username,userpassword);
Statement stmt=conn.createStatement();
String checkInside=(String)session.getValue("insideUser");
if(checkInside==null)
{
session.putValue("insideUser","insideUser");
response.sendRedirect("untitled.jsp");
}
String moveType =request.getParameter("moveButton");
if(moveType==null){}
else if(moveType.equals("next")){
String hiddenName=request.getParameter("user_id");
String sql="select top 1 * from loginuser";
ResultSet rs=stmt.executeQuery(sql);
String name1="";
int recordExist=0;
while(rs.next()){
recordExist=1;
name1=rs.getString("name");
if(name1.equals(hiddenName))
break;
}
if(recordExist==1){
rs=null;
stmt.close();
}
session.putValue("name",name1);
response.sendRedirect("untitled.jsp");
}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>
<body>
</body>
</html>