web后端开发
实现Web端线上投票程序(简易版的改进)
https://blog.csdn.net/m0_74394367/article/details/137904654
web后端开发-实现Web端线上投票程序(简易版)的改进
业务流程实现要求:
1、用户访问投票网站首页index.html,提示用户输入姓名,点击“开始投票”;
2、点击“开始投票”,请求提交至LoginServlet,获取用户姓名,存入session对象,重定向至投票页面“vote.html”;
3、用户选择投票选项(可多选),点击“提交投票”,示例页面如下:

4.点击“提交投票”,请求提交至VoteServlet,获取并保存投票结果后,重定向至“voteseccess.html”;
5. “voteseccess.html”,可以通过超链接查询投票结果;
6.“查询投票结果”提交至ListServlet,显示全部投票结果。
7.采用注解的方式
代码:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>投票首页</title>
</head>
<body>
<p>请输入投票人姓名:</p>
<form action="loginservlet" method="post">
<input type="text" name="user"/><br><br>
<input type="submit" value="开始投票"/>
</form>
</body>
</html>
LoginServlet.java创建servlet文件的URL映射均改为了小写,LoginServlet->loginservlet,VoteServlet->voteservlet,ListServlet->listservlet
package edu.hbun.work5.users;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
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;
//实现Web端线上投票程序
//业务流程实现建议:
//1、用户访问投票网站首页index.html,提示用户输入姓名,点击“开始投票”;
//2、点击“开始投票”,请求提交至LoginServlet,获取用户姓名,存入session对象,重定向至投票页面“vote.html”;
//3、用户选择投票选项(可多选)