【JSP学习笔记】4:使用Model1模式构建购物网站demo

news/2024/5/9 21:55:01/文章来源:https://lauzyhou.blog.csdn.net/article/details/79929187

J2EE课的上机题,实现一个Model1模式的购物网站的功能。

编码问题

编码问题终于找到解决方法了,首先保证每个页面能编码的都编成UTF-8,然后所有用到内置对象的地方上来先.setCharacterEncoding("UTF-8");,然后重要的是在Servers工程(集成了Tomcat的Eclipse里一定有)里,将server.xml中第一个Connector双标签添加属性URIEncoding="UTF-8"

如果添加在了Tomcat的config路径下的server.xml中,每次重启Tomcat都会被这个Servers工程下的文件覆盖,不能永久生效。

数据库部分

product表

这里写图片描述

shop_records表

这里写图片描述

user表

这里写图片描述

MSDBConn.java

package myJDBC;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class MSDBConn {private Statement stmt = null;private java.sql.PreparedStatement ppstmt = null;private Connection conn = null;ResultSet rs = null;// 在构造器中连接public MSDBConn() {try {// 加载驱动Class.forName("com.mysql.jdbc.Driver");// 建立连接String url = "jdbc:mysql://localhost:3306/SHOPDB?useSSL=true&characterEncoding=utf8";conn = DriverManager.getConnection(url, "root", "3838438");} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();}}// 获取Connection对象的引用,方便后面的编程public Connection getConn() {return this.conn;}// 提供做查询的服务public ResultSet executeQuery(String sql) {try {stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);rs = stmt.executeQuery(sql);} catch (SQLException e) {e.printStackTrace();}return rs;}// 提供修改表的服务public int executeUpdate(String sql) {int n = 0;try {ppstmt = conn.prepareStatement(sql);n = ppstmt.executeUpdate();} catch (SQLException e) {e.printStackTrace();}return n;}// 关闭SQL语句对象public void closeStmt() {try {if (stmt != null)stmt.close();if (ppstmt != null)ppstmt.close();} catch (SQLException e) {e.printStackTrace();}}// 关闭连接public void closeConn() {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}
}

POJO

BuyTable.java

package myPOJO;import java.io.Serializable;
import java.sql.Date;//用户购物的表
public class BuyTable implements Serializable {private Integer id;private Integer userId;private Integer productId;private Integer number;private Date shopDate;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public Integer getUserId() {return userId;}public void setUserId(Integer userId) {this.userId = userId;}public Integer getProductId() {return productId;}public void setProductId(Integer productId) {this.productId = productId;}public Integer getNumber() {return number;}public void setNumber(Integer number) {this.number = number;}public Date getShopDate() {return shopDate;}public void setShopDate(Date shopDate) {this.shopDate = shopDate;}}

ShopTable.java

package myPOJO;import java.io.Serializable;
import java.sql.Date;//购物记录表
public class ShopTable implements Serializable {private Integer id;private Integer userId;private Integer productId;private Integer number;private Date shopDate;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public Integer getUserId() {return userId;}public void setUserId(Integer userId) {this.userId = userId;}public Integer getProductId() {return productId;}public void setProductId(Integer productId) {this.productId = productId;}public Integer getNumber() {return number;}public void setNumber(Integer number) {this.number = number;}public Date getShopDate() {return shopDate;}public void setShopDate(Date shopDate) {this.shopDate = shopDate;}
}

UserTable.java

package myPOJO;import java.io.Serializable;//user表
public class UserTable implements Serializable {private Integer id;private String username;private String password;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}

web.mxl

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>t3</display-name><welcome-file-list><welcome-file>first.jsp</welcome-file></welcome-file-list>
</web-app>

JSP页面

这回就能体会到Model1有多么混乱了。

first.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 style="text-align:center;" bgcolor="#CECEFF">
<h1>登录"购物车模拟系统"</h1>
<br/>
<h2>15121856刘知昊</h2>
<br/>
<form action="validate.jsp" method="post"><h3 style="display: inline;">用户名:</h3><input type="text" name="username" size="20"/><br/><br/><br/><br/><h3 style="display: inline;">密码:&nbsp;</h3><input type="password" name="password" size="20"/><br/><br/><input type="submit" value="登录"/><input type="reset" value="重置"/><br/><br/><a href="admin.jsp">转到管理员视角</a>
</form>
</body>
</html>

admin.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="myJDBC.*,java.util.*,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>管理员界面</title>
</head>
<body style="text-align:center;" bgcolor="#CECEFF">
<h1>管理员视角</h1>
*****************************************************************
*****************************************************************
<table align="center" bgcolor="#CEEEFF">
<tr><td><form action="delPeople.jsp" method="post"><table border="1"><caption>用户信息表</caption><tr><th>id</th><th>username</th><th>password</th><th>选定</th></tr><%//建立连接MSDBConn msdbc=new MSDBConn();try{String sql="SELECT * FROM user";ResultSet rs=msdbc.executeQuery(sql);while(rs.next()){%><tr><td><%=rs.getInt(1)%></td><td><%=rs.getString(2)%></td><td><%=rs.getString(3)%></td><td><input type="radio" value="<%=rs.getInt(1)%>" name="delPeo"></td></tr><%}rs.close();}catch(SQLException e){e.printStackTrace();}msdbc.closeStmt();%></table><input type="submit" value="删除"><input type="reset" value="重置"></form></td><td><form action="addPeople.jsp" method="post"><table><caption>添加用户信息</caption><tr><td>用户名:</td><td><input type="text" name="username" size="20"/></td></tr><tr><td>密码:</td><td><input type="password" name="password" size="20"/></td></tr></table><input type="submit" value="添加"><input type="reset" value="重置"></form></td>
</tr>
</table>
*****************************************************************
*****************************************************************
<table align="center" bgcolor="#CEEEFF">
<tr><td><form action="delProduct.jsp" method="post"><table border="1"><caption>商品信息表</caption><tr><th>id</th><th>productCode</th><th>productName</th><th>productSource</th><th>选定</th></tr><%try{String sql="SELECT * FROM product";ResultSet rs=msdbc.executeQuery(sql);while(rs.next()){%><tr><td><%=rs.getInt(1)%></td><td><%=rs.getInt(2)%></td><td><%=rs.getString(3)%></td><td><%=rs.getString(4)%></td><td><input type="radio" value="<%=rs.getInt(1)%>" name="delPro"></td></tr><%}rs.close();}catch(SQLException e){e.printStackTrace();}msdbc.closeStmt();msdbc.closeConn();%></table><input type="submit" value="删除"><input type="reset" value="重置"></form></td><td><form action="addProduct.jsp" method="post"><table><caption>添加商品信息</caption><tr><td>商品编号:</td><td><input type="text" name="productCode" size="20"/></td></tr><tr><td>商品名:</td><td><input type="text" name="productName" size="20"/></td></tr><tr><td>生产公司:</td><td><input type="text" name="productSource" size="20"/></td></tr></table><input type="submit" value="添加"><input type="reset" value="重置"></form></td>
</tr>
</table>
*****************************************************************
*****************************************************************
<br/><br/>
<a href="first.jsp">回到客户登陆视角</a>
</body>
</html>

addPeople.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="myJDBC.*,java.util.*,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>正在处理添加顾客...</title>
</head>
<body><%request.setCharacterEncoding("UTF-8");String username=request.getParameter("username");System.out.println(username);String password=request.getParameter("password");if(username!=null){//建立连接MSDBConn msdbc=new MSDBConn();//插入String sql="INSERT INTO user(username,password) VALUES('"+username+"','"+password+"')";int n=msdbc.executeUpdate(sql);}response.sendRedirect("admin.jsp"); %>
</body>
</html>

addProduct.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="myJDBC.*,java.util.*,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>正在处理添加商品...</title>
</head>
<body><%request.setCharacterEncoding("UTF-8");int productCode=Integer.parseInt(request.getParameter("productCode"));String productName=request.getParameter("productName");String productSource=request.getParameter("productSource");if(productName!=null){//建立连接MSDBConn msdbc=new MSDBConn();//插入String sql="INSERT INTO product(productCode,productName,productSource) VALUES("+productCode+",'"+productName+"','"+productSource+"')";int n=msdbc.executeUpdate(sql);}response.sendRedirect("admin.jsp"); %>
</body>
</html>

addToCar.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="java.util.*"%>
<!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>
<%request.setCharacterEncoding("UTF-8");String id=request.getParameter("productName");//如果session中的哈希表还没建立,建立一下if(session.getAttribute("myShopCar")==null){session.setAttribute("myShopCar", new HashMap<String,Integer>());}//获取session中的哈希表HashMap<String,Integer> hs_sc=(HashMap<String,Integer>)session.getAttribute("myShopCar");if(hs_sc.containsKey(id)==false && id!=null)//实体完整性hs_sc.put(id, 1);else if(id!=null)hs_sc.put(id, hs_sc.get(id)+1);
%><jsp:forward page="main.jsp"/>
</body>
</html>

buyAll.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="myJDBC.*,myPOJO.*,java.util.*,java.sql.*"%>
<jsp:useBean id="nowUser" scope="page" class="myPOJO.UserTable"/>
<!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>
<%//建立连接MSDBConn msdbc=new MSDBConn();//获取购物车中的全部商品if(session.getAttribute("myShopCar")!=null){//获取session中的哈希表HashMap<String,Integer> hs_sc=(HashMap<String,Integer>)session.getAttribute("myShopCar");Iterator iter = hs_sc.entrySet().iterator();//获取表的内容while (iter.hasNext()) {Map.Entry entry = (Map.Entry) iter.next();String key = (String)entry.getKey();Integer val = (Integer)entry.getValue();//获取当前user的JavaBean对象nowUser=(UserTable)session.getAttribute("quote");String sql="INSERT INTO shop_records(userId,productId,number,shopDate) "+"VALUES("+nowUser.getId()+","+key+","+val+",CURDATE())";msdbc.executeUpdate(sql);}}msdbc.closeStmt();msdbc.closeConn();//购买完要清空购物车session.removeAttribute("myShopCar");
%>
<jsp:forward page="main.jsp"/>
</body>
</html>

delPeople.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="myJDBC.*,java.util.*,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>正在处理删除顾客...</title>
</head>
<body><%request.setCharacterEncoding("UTF-8");String id=request.getParameter("delPeo");if(id!=null){//建立连接MSDBConn msdbc=new MSDBConn();//删除String sql="DELETE FROM user WHERE id="+id;int n=msdbc.executeUpdate(sql);}response.sendRedirect("admin.jsp");   %>
</body>
</html>

delProduct.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="myJDBC.*,java.util.*,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>正在处理删除商品...</title>
</head>
<body><%request.setCharacterEncoding("UTF-8");String id=request.getParameter("delPro");if(id!=null){//建立连接MSDBConn msdbc=new MSDBConn();//删除String sql="DELETE FROM product WHERE id="+id;int n=msdbc.executeUpdate(sql);}response.sendRedirect("admin.jsp");   %>
</body>
</html>

delShop.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="java.util.*"%>
<!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>
<%request.setCharacterEncoding("UTF-8");if(session.getAttribute("myShopCar")!=null){//获取session中的哈希表HashMap<String,Integer> hs_sc=(HashMap<String,Integer>)session.getAttribute("myShopCar");//System.out.println(request.getParameter("delShop"));hs_sc.remove(request.getParameter("delShop"));}
%><jsp:forward page="shopcar.jsp"/>
</body>
</html>

error.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>Insert title here</title>
</head>
<body style="text-align:center;" bgcolor="#CECEFF"><br/><br/><br/><br/><br/><br/><br/><br/><h1>[!]用户名或密码错误,点击<a href="first.jsp">这里</a>重新登陆</h1>
</body>
</html>

main.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="myPOJO.*,myJDBC.*,java.util.*,java.sql.*"%>
<jsp:useBean id="nowUser" scope="page" class="myPOJO.UserTable"/>
<!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 style="text-align:center;" bgcolor="#CECEFF">
<%nowUser=(UserTable)session.getAttribute("quote");
%><h1><%=nowUser.getUsername()%>,欢迎来购物!你可以<a href="shopcar.jsp">查看购物车</a>或者<a href="first.jsp">注销</a></h1><%--用js实现的动态显示客户端时间--%><div id="time"><script>document.getElementById('time').innerHTML ="<h2>"+new Date().toLocaleString()+ ' 星期' + '日一二三四五六'.charAt(new Date().getDay())+"</h2>";setInterval("document.getElementById('time').innerHTML=\"<h2>\"+new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay())+\"</h2>\";",1000);</script></div>
*****************************************************************
*****************************************************************<h3>以下是你全部的购买记录,也可以<a href="stat.jsp">查看统计</a></h3><table border="1" align="center" bgcolor="#CEEEFF"><tr><th>订单号</th><th>商品编号</th><th>购买数目</th><th>购买日期</th></tr>   
<%//建立连接MSDBConn msdbc=new MSDBConn();try{String sql="SELECT id,productId,number,shopDate FROM shop_records WHERE userId="+nowUser.getId();ResultSet rs=msdbc.executeQuery(sql);while(rs.next()){%><tr><td><%=rs.getInt(1)%></td><td><%=rs.getInt(2)%></td><td><%=rs.getInt(3)%></td><td><%=rs.getDate(4)%></td></tr>
<%}rs.close();}catch(SQLException e){e.printStackTrace();}msdbc.closeStmt();
%></table>
*****************************************************************
*****************************************************************<h3>现在在售的商品:</h3>   <form action="addToCar.jsp" method="post"><table border="1" align="center" bgcolor="#CEEEFF"><tr><th>额外主键</th><th>商品号</th><th>商品名</th><th>商品制造商</th><th>选定</th></tr>   
<%try{String sql="SELECT * FROM product";ResultSet rs=msdbc.executeQuery(sql);while(rs.next()){
%><tr><td><%=rs.getInt(1)%></td><td><%=rs.getInt(2)%></td><td><%=rs.getString(3)%></td><td><%=rs.getString(4)%></td><td><input type="radio" value="<%=rs.getInt(2)%>" name="productName"></td></tr>
<%}rs.close();}catch(SQLException e){e.printStackTrace();}msdbc.closeStmt();msdbc.closeConn();
%></table><input type="submit" value="添加到购物车"></form>
</body>
</html>

shopcar.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="java.util.*"%>
<!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 style="text-align:center;" bgcolor="#CECEFF"><h1>你的购物车:</h1><form action="delShop.jsp" method="post"><table border="1" align="center" bgcolor="#CEEEFF"><tr><%--TODO --%><th>商品编号</th><th>购买数目</th><th>选定</th></tr>
<% if(session.getAttribute("myShopCar")!=null){//获取session中的哈希表HashMap<String,Integer> hs_sc=(HashMap<String,Integer>)session.getAttribute("myShopCar");Iterator iter = hs_sc.entrySet().iterator();//获取内容while (iter.hasNext()) {Map.Entry entry = (Map.Entry) iter.next();String key = (String)entry.getKey();Integer val = (Integer)entry.getValue();
%><tr><td><%=key%></td><td><%=val%></td><td><input type="radio" value="<%=key%>" name="delShop"></td></tr>
<%}}
%></table><input type="submit" value="从购物车删除"></form><br/><a href="buyAll.jsp"><button>购买购物车中的全部商品</button></a><h4>在这里回到<a href="main.jsp">购物页面</a></h4>
</body>
</html>

stat.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="myPOJO.*,myJDBC.*,java.util.*,java.sql.*"%>
<jsp:useBean id="nowUser" scope="page" class="myPOJO.UserTable"/>
<!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 style="text-align:center;" bgcolor="#CECEFF"><h1>统计视图如下:</h1>
*****************************************************************
*****************************************************************<h3>你在这一周(604800000毫秒)内购买的商品:</h3><table border="1" align="center" bgcolor="#CEEEFF"><tr><th>订单号</th><th>商品编号</th><th>购买数目</th><th>购买日期</th></tr>
<%//当前用户信息nowUser=(UserTable)session.getAttribute("quote");//建立连接MSDBConn msdbc=new MSDBConn();try{String sql="SELECT id,productId,number,shopDate FROM shop_records WHERE userId="+nowUser.getId();ResultSet rs=msdbc.executeQuery(sql);while(rs.next()){java.sql.Date dt=rs.getDate(4);if(System.currentTimeMillis()-dt.getTime()<604800000){
%><tr><td><%=rs.getInt(1)%></td><td><%=rs.getInt(2)%></td><td><%=rs.getInt(3)%></td><td><%=dt%></td></tr>
<%}}rs.close();}catch(Exception e){e.printStackTrace();}finally{msdbc.closeStmt();}
%></table>*****************************************************************
*****************************************************************<h3>按照商品的productId分类展示你的全部购买记录:</h3><table border="1" align="center" bgcolor="#CEEEFF"><tr><th>订单号</th><th>商品编号</th><th>购买数目</th><th>购买日期</th></tr>
<%try{String sql="SELECT id,productId,number,shopDate FROM shop_records WHERE userId="+nowUser.getId()+" ORDER BY productId";ResultSet rs=msdbc.executeQuery(sql);while(rs.next()){
%><tr><td><%=rs.getInt(1)%></td><td><%=rs.getInt(2)%></td><td><%=rs.getInt(3)%></td><td><%=rs.getDate(4)%></td></tr>
<%}rs.close();}catch(Exception e){e.printStackTrace();}finally{msdbc.closeStmt();msdbc.closeConn();}
%></table><h4>在这里回到<a href="main.jsp">购物页面</a></h4>
</body>
</html>

validate.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="java.sql.*,myPOJO.UserTable"%>
<%--懒得创建对象就使用JavaBean--%>
<jsp:useBean id="msdbc" scope="page" class="myJDBC.MSDBConn"/>
<jsp:useBean id="nowUser" scope="page" class="myPOJO.UserTable"/>
<!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>
<%boolean validated=false;request.setCharacterEncoding("UTF-8");String usr=request.getParameter("username");String pwd=request.getParameter("password");//当已经有了session,且没有输入用户名或输了相同的用户名时免验证if(session.getAttribute("quote")!=null && (usr.length()<=0 || usr.equals(((UserTable)session.getAttribute("quote")).getUsername()))){validated=true;//这个其实可以去掉
%><jsp:forward page="main.jsp"/>
<%}//通过数据库进行验证else{//在验证前清空session,考虑到换号登陆session.removeAttribute("quote");//调试输出System.out.println(usr);System.out.println(pwd);String sql="SELECT id,password FROM user WHERE username='"+usr+"'";ResultSet rs=msdbc.executeQuery(sql);Integer id=null;String realpwd=null;while(rs.next()){realpwd=rs.getString(2);if(realpwd.compareTo(pwd)==0){id=rs.getInt(1);validated=true;}}rs.close();msdbc.closeStmt();msdbc.closeConn();//如果验证成功if(validated){nowUser.setId(id);nowUser.setUsername(usr);nowUser.setPassword(realpwd);//保存在session里session.setAttribute("quote",nowUser);
%><jsp:forward page="main.jsp"/>
<%}else{
%><jsp:forward page="error.jsp"/>
<%}}
%>
</body>
</html>

测试运行

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_803607.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

搭建网站必不可少的知识15

网站迁移 备份网站和数据库 在服务器上将网站文件拷贝到另一个文件夹 数据库部分打开phpmyadmin 进入phpboke数据库&#xff0c;点击“导出”进行“执行” 选择数据库要保存的位置&#xff0c;进行保存 网站恢复当我们更换服务商或者系统时进行了网站和数据库的备份&#xff0c…

HTTrack(网站镜像工具)

1、首先打开kali 中的这个工具 Web信息收集工具HTTrack ,会直接出现出现使用语法。 对于传统的像存在Robots.txt的网站&#xff0c;如果程序运行的时候不做限制&#xff0c;在默认的环境下程序不会把网站镜像&#xff0c;简单来说HTTPrack跟随基本的JavaScript或者APPLet、flas…

我的网站搭建: (第十天) Ueditor后台编辑器

之前说过&#xff0c;我的网站编辑器一开始是tinymce&#xff0c;然后才用的ckeditor。可是最近我发现&#xff0c;ckeditor的小图标不是很美观&#xff0c;看久了有点low的样子。我是不是应该换一个编辑器呢&#xff0c;一想到这里&#xff0c;马上打开谷歌搜索有没有更加美观…

Java Web性能测试 - 动态网站测试脚本录制

Java Web性能测试 - 动态网站测试脚本录制 本章讲解使用Badboy对网站的请求进行录制&#xff0c;录制完成的脚本文件可以直接用JMeter使用&#xff0c;免去在JMater中进行配置的时间。 使用Badboy录制基本的目的就是减少我们在使用JMeter测试WEB项目时&#xff0c;一个一个Url…

Java Web项目性能测试 - JMeter测试网站吞吐量、反应时间百分比、流量

Java Web项目性能测试 - JMeter测试网站吞吐量、反应时间百分比、流量 为了衡量、调整、完成Java Web项目的性能指标&#xff0c;满足客户、用户对性能的要求&#xff0c;保证项目上线后能正常运行&#xff0c;以及了解项目的性能指标&#xff0c;为项目性能监控做参考&#x…

Java图片水印生成器代码 - 批量给自己的网站图片加水印

Java图片水印生成器代码 - 批量给自己的网站图片加水印 最近在做一款APP&#xff0c;App中的图片是自己一个个的画出来的&#xff0c;为了保证图片不被盗用和处理&#xff0c;所以就需要加上水印防盗。这跟CSDN一样。 注意事项&#xff1a;1. 我是在window7 eclipse 下完成的…

阿里云云虚拟主机上个人网站的Https访问配置

本文基于阿里云云虚拟主机,我个人网站是基于Hexo博客系统搭建的静态网站,所以搭建Https相对方便 一、获取HTTPS安全证书 在操作之前&#xff0c;请将你的域名的隐私保护去掉&#xff0c;让证书服务商能通过域名解析查看到域名管理者的邮箱&#xff0c;否则验证证书时会无法进行…

阿里云服务提供商分享视频直播网站服务器解决方案

大家应该都听过抖音、西瓜视频这类的视频网站&#xff0c;而且这些视频网站深受大家喜爱。直播模式也如雨后春笋一般快速出现&#xff0c;电商直播也逐渐火热。因此很多视频类公司纷纷搭建视频直播平台&#xff0c;那么这类网站的服务器该如何选择呢&#xff1f;下面就由阿里云…

使用Charles代理工具导致电脑无法正常访问网站(您的连接不是私密连接)

很多开发者都需要使用代理工具来调试接口&#xff0c;查看数据等等&#xff0c;但是有时候发现打开代理工具之后&#xff0c;代理工具同时也拦截了电脑的所有网络请求&#xff0c;导致电脑访问网站时提示&#xff08;您的连接不是私密连接&#xff09;。。。 造成这种问题的原因…

大型网站技术架构(七)网站的可扩展性架构

2019独角兽企业重金招聘Python工程师标准>>> 扩展性是指对现有系统影响最小的情况下&#xff0c;系统功能可持续扩展或提升的能力。 设计网站可扩展架构的核心思想是模块化&#xff0c;并在此基础上&#xff0c;降低模块间的耦合性&#xff0c;提供模块的复用性。模…

新书推荐:网站交互设计模式

新书推荐&#xff1a;网站交互设计模式【作  者】(美)Douglas K.Van Dugne;James A.Landay;Jason I.Hong [同作者作品] [作译者介绍] 【译  者】 孙昕;焦洪[同译者作品] 【出 版 社】 电子工业出版社 【书 号】 9787121092046 【上架时间】 2009-7-24 【出版日期】…

html5游戏网站欣赏,70多个HTML5网站设计欣赏

70多个HTML5网站设计欣赏7月 6, 2011评论SponsorHTML5网站确实很不错&#xff0c;能帮助设计师解决很多美化问题外&#xff0c;还能提高更好的用户体验&#xff0c;制作出高效的网站&#xff0c;所以我们应该开始学习CSS3和HTML5这些技术了&#xff0c;不要老是被国外超越我们&…

高并发、高可用、大数据量网站系统演化

一、初始阶段的网站架构 应用程序、数据库、文件等所有资源都在一台服务器上 二、应用服务和数据库服务分离 整个网站使用三台服务器&#xff1a;应用服务器、文件服务器、数据库服务器 应用服务器需要更强大的CPU 文件服务器需要更大的磁盘空间 数据库服务器需要更快的硬盘和更…

WordPress网站漏洞利用及漏洞修复解决方案

2019年正月刚开始&#xff0c;WordPress最新版本存在远程代码注入获取SHELL漏洞&#xff0c;该网站漏洞影响的版本是wordpress5.0.0&#xff0c;漏洞的产生是因为image模块导致的&#xff0c;因为代码里可以进行获取目录权限&#xff0c;以及文件包含功能&#xff0c;导致远程代…

docker容器源码部署httpd,用存储卷部署网站

docker容器源码部署httpd&#xff0c;用存储卷部署网站 创建一个httpd镜像 // 创建一个httpd容器 [rootlocalhost ~]# docker run -tid --name httpd centos 2d693e16f4f3734b127cbae90d189c1b4e78619a54ceec912a82d96cf4f1c345 [rootlocalhost ~]# docker ps CONTAINER ID …

java jsoup爬取动态网站_java笔记|爬取华软mysise所有课程信息

本次内容&#xff1a;使用java爬取网页数据&#xff0c;并进行数据清洗&#xff0c;熟悉爬取操作&#xff1b;爬取华软课程信息&#xff1a;http://class.sise.com.cn:7001/sise/index.jsp//源码package com.sise.studentInfoSystem.demo;import com.sise.studentInfoSystem.be…

win7关于无线连接的服务器,win7怎样解除无线连接限制_网站服务器运行维护,win7,无线连接...

win10系统如何重置密码_网站服务器运行维护win10系统重置密码的方法是&#xff1a;1、右键点击开始图标&#xff1b;2、在弹出的选项列表中&#xff0c;点击选项【Windows PowerShell(管理员)】&#xff1b;3、执行命令【net user 用户名 新密码】即可。win7解除无线连接限制的…

网站服务器和seo,网站所在服务器与网站SEO排名之间的关系

想让你的网站在搜索引擎中获得好的排名&#xff0c;得到更多的客户认可。作为一个合格的SEOer&#xff0c;你就得把网站服务器作为一个重要事项来做。大家都知道网站是由域名、服务器及页面文件组成的&#xff0c;从这个你也就可以看出服务器的重要性。SEO优化包含的面非常广&a…

java 热点词排名_利用seo技术排名热点新闻词引流(日IP增加2万+)

一个很普通的热点&#xff0c;很容易被各大媒体平台炒到高流量&#xff0c;所以很多人希望能够通过新闻热点来蹭到一部分流量&#xff0c;但大多数的情况下&#xff0c;百度上的新闻热点内容都被大平台拿走了&#xff0c;咱们今天也来教教大家&#xff0c;如何拿到一部分热点流…

调试-Chrome删除某个特定网站的Cookie

方法1 设置 → 高级 → 隐私设置和安全性 → 网站设置 → Cookie和网站数据 → 查看所有Cookie和网站数据 方法2 设置 → 搜索框中输入“Cookie”→ 根据提示一个个点开选项卡找即可