网站系统开发需要掌握的技术:html/java Script/jsp/sql 语句
源程序代码:
Login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>请登录</title>
</head>
<body>
<h2 align = "center">请登录</h2>
<form name = "form1" action = "check.jsp" method = "post">
<table align = "center">
<tr>
<td>请输入用户名:</td>
<td><input type = "text" name = "id"></td>
</tr>
<tr>
<td>请输入密码:</td>
<td><input type = "password" name ="pass"></td>
</tr>
<tr><td><input type = "reset" value = "重置" ></td>
<td><input type = "submit" value = "提交"></td>
</table>
</form>
</body>
</html>
Check.jsp
<%@ page language="java" import="java.sql.*"
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>Insert title here</title>
</head>
<body>
<%
String id = request.getParameter("id");
String pass = request.getParameter("pass");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection
("jdbc:mysql://localhost:3306/byke","root","hanhan");
Statement stmt=con.createStatement();
String s="select * from user";
ResultSet rs;
rs=stmt.executeQuery(s); //执行查询语句
rs.next();
if(rs.getString(1).equals(id)&&rs.getString(2).equals(pass)){
response.setHeader("refresh","1;url=sucess.jsp");
}
else
{
out.println("<script language='javaScript'> alert('登陆失败,点击确定重新登陆!');</script>");
response.setHeader("refresh","1;url=login.html");
}
%>
</body>
</html>
Success.jsp
<%@ page contentType="text/html;charset=GB2312"%>
<html>
<head>
<title>登录成功</title>
</head>
<body>
<%
if(application.getAttribute("count")==null)
{
application.setAttribute("count", new Integer(0));
}
Integer count= (Integer)(application.getAttribute("count"));
application.setAttribute("count", new Integer(count.intValue()+1));
%>
<h2>欢迎你访问,本页已经被访问过<font color="#ff0000"><%=application.getAttribute("count") %></font>次</h2>
</body>
</html>
Fail.jsp
<%@ page contentType="text/html;charset=GB2312"%>
<html>
<head>
<title>登录失败</title>
</head>
<body>
<h2>用户名或者口令不正确,请<a href="login.html">重新登录!</a></h2>
</body>
</html>
截图:
课堂测试未完成的原因:不会数据库操作
对这门课的期望和目标:学会制作网页