文章目录
运行环境
- windows10
- IDEA专业版
- JDK8
- HTML5、CSS3、JavaScript
- JQuery
- Bootstrap5
1. 页面效果展示
1.1 登陆信息错误提示
1.2 文字验证码
1.3 用户查询自己发布的商品
2. 功能实现
2.1 文字验证码
2.1.1 JSP页面代码
<div class="row">
<label for="ck" class="col-md-2 offset-md-1 fs-4">
<a href="/code" style="list-style-type: none; color: black">验证码</a>
</label>
<div class="col-md-7 order-md-2">
<input type="text" id = "ck" name="ck" class="form-control w-100" placeholder = "${sessionScope.problem}">
</div>
</div>
2.1.2 Servlet类
CodeACtion.java
该类负责产生随机的两个100以内的数字,最后进行加法运算,将两个数字的相加作为问题字符串存入session域的problem对象,然后将相加的结果存入session域的answer对象,最终在前端页面直接判断即可。
package com.uni.action;
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 javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Random;
@WebServlet(name = "CodeAction", urlPatterns = "/code")
public class CodeAction extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
int a = new Random().nextInt(100);
int b = new Random().nextInt(100);
int c