jsp网页登陆验证(2)

package cn.mike.servlet.test_1212; import java.awt.image.BufferedImage; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import cn.mike.javase.test.VerificationCode; public class GetVerificationCodeServlet extends HttpServlet { private static final long serialVersionUID = -3520994675366100452L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 1.新建一个VerificationCode类; VerificationCode vc = new VerificationCode(); // 2.从VerificationCode类中获取BufferedImage对象; BufferedImage bufImage = vc.getImage(); // 3.同时获取验证码中的文本内容,并放到session域中, 用于校验; String code_text = vc.getText(); request.getSession().setAttribute("code_text", code_text); // 4.将生成的图片输出到客户端浏览器 VerificationCode.output(bufImage, response.getOutputStream()); }// end method-doGet public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // do same as GET-method : doGet(request, response); }// end method-doPost }

part_4:成功登陆后的提示界面1:success-page-1.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "https://www.jb51.net/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.jb51.net/<%=basePath%>"> <title>My JSP 'success-page-1.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link type="text/css" href="https://www.jb51.net/styles.css"> --> </head> <% String username = (String) session.getAttribute("username"); if (null == username) { //如果username为空值,说明不是通过正常渠道来的,转发到Login页面; request.setAttribute("fdbkMsg", "别想走后门进来,赶紧登录!"); request.getRequestDispatcher("/LOGIN-DEMO/Login.jsp").forward( request, response); } %> <body> <br> <%=username%>已经成功登陆。 <br> <font>您可以选择浏览:</font> <br> <a href="https://www.jb51.net/ServletDemoProject/LOGIN-DEMO/success-page-2.jsp">点这儿有精彩.</a> <br> <a href="https://www.jb51.net/ServletDemoProject/LOGIN-DEMO/success-page-2.jsp">点这儿更精彩.</a> <br /> <a href="https://www.jb51.net/ServletDemoProject/LOGIN-DEMO/success-page-2.jsp">你敢点这儿吗.</a> <br /> </body> </html>

part_5:成功登陆后的提示界面1:success-page-2.jsp

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjxdw.html