为了练手,我就自己试着做了一个网站的登录与注册的小案例。由于没有做美化处理,所以界面并不是很好看。

网站实现的功能如下:

"htmlcode">

<%@ 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>User to Register Page!</title>
</head>
<body>
<hr><br>Welcome to this <font color="green">Enroll(Register) Page</font>!<br>
<form action="do_register.jsp" method="get">
<br>
<h1>Please input your message:</h1><br>
Name:<input type="text" name="register_name"><br>
Pswd:<input type="password" name="register_password"><br>
<br><br><br>
<input type="submit">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"><br>
</body>
</html>

然后就是action对应的注册处理页,如下do_register.jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<!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>Server to do the register page!</title>
</head>
<body>
<%
 String Register_name=request.getParameter("register_name");
 String Register_password=request.getParameter("register_password");
%>

<%
try{
 Class.forName("com.mysql.jdbc.Driver");
 Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/summer", "root", "mysql");
 Statement stmt=conn.createStatement();
 //desogn the sql statement
 String InsertSQL="INSERT INTO User(Name,Password) values('"+Register_name+"','"+Register_password+"')";
 System.out.println(Register_name+"\t"+Register_password);


 //do the query operation,and here is the most important sql statement. 
 int FLAG=stmt.executeUpdate(InsertSQL);

 if(FLAG>0){
 response.getWriter().write("Congratulation! REgister Success!");
 }else{
 response.getWriter().write("Sorry!Register Failed!\nPlease Retry it!");
 }
}catch(SQLException e){

}
%>


</body>
</html>

小总结:
不足之处:
 "htmlcode">

<%@ 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>User Login Page</title>
</head>
<body>

<hr><br>Welcome to this <font color="green">Login Page</font>!<br>
<form action="do_login.jsp" method="get">
<br>
<h1>Please input your message:</h1><br>
Name:<input type="text" name="name"><br>
Pswd:<input type="password" name="password"><br>
<br><br><br>
<input type="submit">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"><br>
Click me to <font color="green"><a href="register.jsp">Register</a>!</font><br>


</form>

</body>
</html>

然后是对登录信息的处理页,do_login.jsp:

<%@page import="java.sql.DriverManager"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<!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>Server Page Depend !</title>
</head>
<body>
<h3>Which Pae will be depend by the user's message!</h3>

<%
 String name=request.getParameter("name");
 String password=request.getParameter("password");
%>


<%
 Class.forName("com.mysql.jdbc.Driver");
 Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/summer", "root", "mysql");
 Statement stmt=conn.createStatement();
 //desogn the sql statement
 String queryNumberSQL="SELECT Name from User where Name='"+name+"' and Password='"+password+"'";
 //do the query operation
 ResultSet rs=stmt.executeQuery(queryNumberSQL);
 boolean flag=false;
 if(rs.next()){
 flag=true;
 session.setAttribute("UserName", name);
 }else{
 flag=false;
 }

%>
<%
 if(flag){
%>
<jsp:forward page="login_success.jsp"></jsp:forward>
<%
 }else{

%>
<jsp:forward page="login_failed.jsp"></jsp:forward>
<%
 }
%>



</body>
</html>

对于登陆成功的用户,跳转到登陆成功界面login_success.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>User Login Success Page!</title>
</head>
<body>
<hr><br>
<h1>Login Success!</h1><br>
<font color="green">Welcome <%=session.getAttribute("UserName") %>!</font>

<h3 align="center">your persional Message is:</h3>
<%
 out.println("Name:"+session.getAttribute("UserName"));
%>
<font color="red"><a href="login.jsp">Click me</a> to log out!</font>

</body>
</html>

对于登录失败的用户,进行温馨的页面提示,login.failed.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>Login Failed Page!</title>
</head>
<body>
<hr>
<br>
<h1><font color="red">Sorry,Login Failed</font></h1><br>
<font color="red"><a href="login.jsp">Click me</a> to login!</font>
</body>
</html>

大总结:

进步之处:

 "color: #800000">不足之处:

 "color: #800000">待改进之处:

 •加上复杂一点的用户注册,使用bean的方式做处理比较好
 •模块化,使用MVC的概念
 •改善界面的权限,防止盗链
 •加上其他的诸如上传文件,下载文件功能,丰富网站的功能。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。