赞
踩
给buttont添加点击事件,匿名函数中将商品id作为参数传递给AddshowinfoServlet
通过传递过来的id查询商品表的数据,将查询出的商品封装到session中,请求转发到shopinfo.jsp页面
自己业余时间瞎琢磨的,还有许多功能未实现,仅供参考
2.使用IDEA开发工具 + jsp + mybatis 框架 +mysql数据库 + javaScipt +jquery
3.数据库中的数据准备
- <%@ page contentType="text/html;charset=UTF-8" language="java" %>
- <html>
- <head>
- <title>登录页面</title>
- <link rel="stylesheet" href="./css/style.css" type="text/css">
- </head>
- <body>
- <div class="login-form-wrap">
- <h1>登录页面</h1>
- <form class="login-form" action="/cookie/UserServlet" id="regist" method="get" autocomplete="off">
- <label>
- <input type="text" id="username" name="username" placeholder="Username" value="">
- </label>
- <label>
- <input type="password" id="password" name="password" placeholder="Password" value="">
- </label>
- <input type="submit" value="登录">
- <a href="./regist.jsp">未注册?点击注册</a>
- </form>
- </div>
- </body>
- <script>
- //1.为表单登录绑定提交事件
- document.getElementById("regist").onsubmit = function() {
- //2.获取填写的用户名和密码
- let username = document.getElementById("username").value;
- let password = document.getElementById("password").value;
-
- //3.判断用户名是否符合规则
- let reg1 = /^[a-zA-Z]{4,16}$/;
- if(!reg1.test(username)) {
- alert("用户名不符合规则,请输入4 ~ 16位纯字母!");
- return false;
- }
-
- //4.判断密码是否符合规则
- let reg2 = /^[\d]{6}$/;
- if(!reg2.test(password)) {
- alert("密码不符合规则,请输入6位纯数字密码!");
- return false;
- }
- //5.如果所有条件都不满足,则提交表单
- return true;
- }
- </script>
- </html>
- package com.hbsi.controller;
- import com.hbsi.bean.User;
- import com.hbsi.service.UserService;
- import com.hbsi.service.impl.UserServiceImpl;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.util.List;
- @WebServlet("/UserServlet")
- public class UserServlet extends HttpServlet {
- UserService service=new UserServiceImpl();
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- req.setCharacterEncoding("UTF-8");
- resp.setCharacterEncoding("UTF-8");
- resp.setContentType("text/html;charset=UTF-8");
- String username = req.getParameter("username");
- String password = req.getParameter("password");
- User user=new User(username,password);
- User user1= service.selectUsermassage(user);
- //判断用户名
- if(username==null || "".equals(username)) {
- //2.1用户名为空,重定向到登录页面
- resp.sendRedirect("/cookie/login.jsp");
- return;
- }
- //2.2 用户名不为空,将用户名存入到绘话域
- if(user1 != null) {
- req.getSession().setAttribute("user1", user1);
- resp.sendRedirect("/cookie/usermassage.jsp");
- }else {
- req.setAttribute("msg","该用户名未注册或密码错误!!!");//封装请求属性
- req.getRequestDispatcher("login.jsp").forward(req,resp);
- }
- }
-
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- doGet(req, resp);
- }
- }
-
- <%@ page contentType="text/html;charset=UTF-8" language="java" %>
- <html>
- <head>
- <title>注册页面</title>
- <link rel="stylesheet" href="./css/regist01.css" type="text/css">
- </head>
- <body>
- <div class="regist-form-div">
- <h1>注册新用户</h1>
- <form class="regist-form" action="${pageContext.request.contextPath}/registservlet" id="regist" method="get" autocomplete="off">
- <label>
- <input type="text" id&
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。