基本信息
源码名称:jsp web登陆页 入门示例
源码大小:0.21M
文件格式:.zip
开发语言:Java
更新时间:2016-01-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package wuyuanyuan.test.com; import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class LoginServlet extends HttpServlet { HashMap<String, String> account = new HashMap<String, String>(); protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { // 设置相应的类型为text/html response.setContentType("text/html;charset=utf-8"); // 对于get方式 获取请求文本参数的方法 getParameter(对应的键) String username = request.getParameter("username"); String password = request.getParameter("password"); // 对客户端请求的数据进行操作 System.out.println(username); boolean flag = isValid(username, password); String res = ""; if (flag) res = "登录成功"; else res = "用户名或密码错误"; // 从HttpServletResponse得到输出流 PrintWriter out = response.getWriter(); // 向客户端打印HTML文本 out.write("<div>" res "</div>"); // 输出并关闭流 out.flush(); out.close(); } private boolean isValid(String username, String password) { account.put("admin", "admin"); account.put("admin1", "admin1"); account.put("admin2", "admin2"); return password.equals(account.get(username)); } }