JSP课程设计

发布时间:2023年12月26日

目录

一.题目

二.相关技术

三.部分页面数据展示

四.整体流程图

五.部分代码



一.题目

????????网站包括5个栏目,整个站点的网页数不少于6个,网站具有用户登录、新用户注册、删除用户、修改用户信息等功能。用户登录网站后可以购买物品(航天纪念品),并能够查看购物车。

二.相关技术

1.使用JSP、JAVASCRIPT、CSS设计网站;

2.MVC设计模式;?

3.JSP+JDBC访问数据库实现增删改查操作;

4.使用JavaScript、CSS制作页面特效 ;

5.JSP、MySQL、JavaScript、CSS等。

三.部分页面数据展示

四.整体流程图

五.部分代码

@WebServlet("/Controller2")
public class Controller2 extends HttpServlet {
????@Override
????protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
????????this.doPost(req, resp);
????}


????@Override
????protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
????????resp.setContentType("text/html;charset=utf-8");
????????PreparedStatement ptst=null;
????????Statement stmt=null;
????????Connection conn=null;
????????ResultSet rs=null;

????????String name=req.getParameter("name");
????????String password=req.getParameter("password");

????????String name2="SELECT NAME FROM user";
????????String password2 = "SELECT PASSWORD FROM user WHERE NAME=?";

????????User user=new User();
????????user.setName(name);
????????user.setPsssword(password);

????????try {
?????????????//获取数据库连接

conn= JDBCUtils.getConnection();
????????????//获取statement对象
????????????stmt=conn.createStatement();
????????????//使用statement对象执行SQL语句,返回表示查询结果的ResultSet对象
????????????rs=stmt.executeQuery(name2);
????????????String username=null;
????????????String Name=null;
????????????//遍历数据库中的信息,查找是否有该用户
????????????while (rs.next()){
????????????????username = rs.getString("NAME");
????????????????if (username.equals(name)) {
????????????????????Name = username;
????????????????}
????????????}
????????????//没有找到该用户,给出提示并转发到登录页面重新登录
????????????if(Name==null) {
????????????????????req.setAttribute("warn2","该用户名不存在");
????????????????????req.setAttribute("USER",user);
????????????????????req.getRequestDispatcher("login.jsp").forward(req,resp);
????????????????????return;
????????????????}
????????????????ptst = conn.prepareStatement(password2);
????????????????ptst.setString(1, name);
????????????????rs = ptst.executeQuery();
????????????????//判断输入的该用户的密码是否正确
????????????????while (rs.next()) {
????????????????????String Password = rs.getString("PASSWORD");
????????????????????if (Password.equals(password)) {
????????????????????????//登录成功后设置一个cookie用于判断是否能够购物
????????????????????????Cookie cookie = new Cookie("flag", "true");
????????????????????????resp.addCookie(cookie);
????????????????????????resp.sendRedirect("Select.jsp");
????????????????????????JOptionPane.showMessageDialog(null, "登录成功!");
????????????????????} else {
????????????????????????req.setAttribute("warn1", "密码错误,请重新输入");
????????????????????????req.setAttribute("USER",user);
????????????????????????req.getRequestDispatcher("login.jsp").forward(req, resp);
????????????????????}
????????????????}
????????} catch (Exception e) {
????????????e.printStackTrace();
????????}finally {
????????????JDBCUtils.release(rs,stmt,conn);
????????}

????}

}

<table ??class="center-block" style="width:400px;" >
????<form align="center" ?role="form" method="post " action="Controller2" >
????????<h2 class="text-center">登录</h2>
????????<hr>
????????<div class="input" style="padding: 10px 300px ;">
????????????<label>用户名
????????????????<label style="color:red;">*</label>
????????????</label>
????????????<input class="form-control " name="name" type="text" value="${USER.name}">
????????????<span>${warn2}</span>
????????</div>
????????<div class="input" style="padding: 10px 300px ;">
????????????<label>密码
????????????????<label style="color:red;">*</label>
????????????</label>
????????????<input class="form-control " name="password" ?type="password" ??>
????????????<span>${warn1}</span>
????????</div>
????????<div style="text-align: center;padding: 20px 0" >
????????????<input type="submit" />???????<input type="reset" />
????????</div>
????</form>
</table>

代码以及相关资料

文章来源:https://blog.csdn.net/qq_53247869/article/details/135210332
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。