• JSP 09


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>用户注册</title>
    <style type="text/css">
        span{
            color:gray;
        }
    </style>
    </head>
    
    <body>
    <FORM action="info.jsp" method="post" name="myform">
    <TABLE   border="0" cellpadding="0" cellspacing="0" align="center" width="530">
      <TR>
        <TD width="107" height="36">用户名:</TD>
        <TD width="524"><INPUT name="txtUser" type="text" maxlength="16"><span>只能输入字母或数字,3-16个字符</span></TD>
      </TR>
        <TR>
        <TD width="107" height="36">密码:</TD>
        <TD width="524"><INPUT name="txtPass" type="password"><span>密码长度6-12位</span></TD>
      </TR>
        <TR>
        <TD width="107" height="36">确认密码:</TD>
        <TD width="524"><INPUT name="txtRPass" type="password"></TD>
      </TR>
        <TR>
        <TD width="107" height="36">性别:</TD>
        <TD width="524">
            <INPUT name="gen" type="radio"   value="男" checked>&nbsp; 
            <INPUT name="gen" type="radio" value="女" class="input"></TD>
      </TR>
        <TR>
        <TD width="117" height="36">电子邮件地址:</TD>
        <TD width="524"><INPUT name="txtEmail" type="text"><span>输入正确的Email地址</span>
        </TD>
      </TR>
      <TR><TD colspan="2" align="center">
      <INPUT type="submit" value="同意以下协议条款并提交">
      </TD></TR>
      <TR><TD colspan="2">
      <TEXTAREA cols="" rows="" readonly="readonly" style="480px;height:110px;font-size:12px;color:#666">
    一、总则
    
    1.1 用户应当同意本协议的条款并按照页面上的提示完成全部的注册程序。用户在进行注册程序过程中点击"同意"按钮即表示用户达成协议,完全接受本协议项下的全部条款。
    1.2 用户注册成功后,将给予每个用户一个用户帐号及相应的密码,该用户帐号和密码由用户负责保管;用户应当对以其用户帐号进行的所有活动和事件负法律责任。
    1.3 用户可以使用百度各个频道单项服务,当用户使用各单项服务时,用户的使用行为视为其对该单项服务的服务条款在该单项服务中发出的各类公告的同意。
    1.4 服务协议以及各个频道单项服务条款和公告可由百度公司随时更新,且无需另行通知。您在使用相关服务时,应关注并遵守其所适用的相关条款。
      您在使用Email提供的各项服务之前,应仔细阅读本服务协议。如您不同意本服务协议及/或随时对其的修改,您可以主动取消百度提供的服务;您一旦使用服务,即视为您已了解并完全同意本服务协议各项内容,包括对服务协议随时所做的任何修改,并成为百度用户。
            </TEXTAREA>
      </TD>
      </TR>
    </TABLE>
    </FORM>
    </body>
    </HTML>
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>用户登录</title>
    <style type="text/css">
        span{
            text-decoration:underline;
            color:blue;
        }
        div{
        color: red;
        }
    </style>
    </head>
    <script type="text/javascript">
        window.onload=function(){
            var i=0;
            var yzm=document.getElementById("yzm");
            yzm.onclick=function(){
                i++;
                yzm.src="/web_homework/yzm?"+i;
                
            }
            var span=document.getElementById("span");
            span.onclick=function(){
                yzm.onclick();
                
            } 
        }
    </script>
    <body>
        <form action="/web_homework/testServlet" method="post">
            <input type="text" id="username" name="username" value="yxy"><br>
            <input type="password" id="password" name="password" value="123456"><br>
            <input type="text" name="yzm_text" placeholder="看清图片再输入"><br>
            <img alt="这是一张验证码" src="/web_homework/yzm" id="yzm"><span id="span">看不清!换一张</span><br>
            <input type="submit" value="登录">
        </form>
        <div><%=request.getSession().getAttribute("yzm_error")==null?"":request.getSession().getAttribute("yzm_error")%></div>
        <div><%=request.getSession().getAttribute("user_error")==null?"":request.getSession().getAttribute("user_error")%></div>
        <%request.getSession().removeAttribute("yzm_error"); 
        request.getSession().removeAttribute("user_error"); %>
    </body>
    </html>
    <%@page import="domain.Email"%>
    <%@page import="java.util.List"%>
    <%@page import="Dao.UserDao"%>
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>欢迎登录</title>
    <style type="text/css">
        td{
            border: 1px solid;
            text-align: center;
        }
    </style>
    </head>
    <script type="text/javascript">
        window.onload=function(){
            var zx=document.getElementById("zx");
            zx.onclick=function(){
                alert("确定退出?");
                document.getElementById("a").href="/web_homework/exit";
            }
        }
    </script>
    <body>
        <%
            String name=(String)request.getSession().getAttribute("name");
        %>
              <p align="center">欢迎登录,<%=name %>的邮箱<span><a id="a" href="#"><input type="submit" value="注销" id="zx"></a></span></p>
        <%
        UserDao dao=new UserDao();
        List<Email> emails=dao.queryYxyEmail();
        %>
        <table align="center">
            <tr>
                <td>id &nbsp;&nbsp;&nbsp;</td>
                <td>title&nbsp;&nbsp;&nbsp;</td>
                <td>content&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>sendto&nbsp;&nbsp;&nbsp;</td>
                <td>state&nbsp;&nbsp;&nbsp;</td>
                <td>send_date&nbsp;&nbsp;&nbsp;</td>
                <td>操作</td>
            </tr>
           <%
                   for(Email e:emails){
                       %><tr><%
                       %><td><%=e.getId() %></td><%
                       %><td><%=e.getTitle() %></td><%
                       %><td><%=e.getContent() %></td><%
                       %><td><%=e.getSendto() %></td><%
                       %><td><%=e.getState() %></td><%
                       %><td><%=e.getSend_date() %></td><%
                       %><td><a href="#">查看</a>&nbsp;&nbsp;<a href="#">回复</a>&nbsp;&nbsp;<a href="#">删除</a></td><%
                       %></tr><%
                   }
           %>    
        </table>
    </body>
    </html>
    package servlet;
    
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.util.Random;
    
    import javax.imageio.ImageIO;
    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.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class yzm
     */
    @WebServlet("/yzm")
    public class yzm extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public yzm() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            //创建图片对象
            int width=100;
            int height=50;
            BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
            //获取画笔
            Graphics g = image.getGraphics();
            //填充背景颜色
            g.setColor(Color.PINK);
            g.fillRect(0, 0, width, height);
            //画蓝色边框
            g.setColor(Color.BLUE);
            g.drawRect(0, 0, width-1, height-1);
            //生成随机字母数字,利用循环写入,同时保存session
            String str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            Random r = new Random();
            g.setColor(Color.RED);//红色字
            StringBuilder sBuilder=new StringBuilder();
            for (int i = 0; i < 4; i++) {
                int index = r.nextInt(str.length());
                char ch = str.charAt(index);
                g.drawString(ch+"", width/5+i*20, height/2);//调整位置
                sBuilder.append(ch);
            }
            String yzm_session = sBuilder.toString();
            request.getSession().setAttribute("yzm_session", yzm_session);
            //画干扰线绿色
            g.setColor(Color.GREEN);
            for (int i = 0; i < 10; i++) {
                int x1 = r.nextInt(width);
                int x2 = r.nextInt(width);
                int y1 = r.nextInt(height);
                int y2 = r.nextInt(height);
                g.drawLine(x1, y1, x2, y2);
            }
            //输出图像展示到网页
            ImageIO.write(image, "jpg", response.getOutputStream());
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request, response);
        }
    
    }
    package servlet;
    
    import java.io.IOException;
    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;
    
    /**
     * Servlet implementation class TestServlet
     */
    @WebServlet("/testServlet")
    public class TestServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public TestServlet() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            request.setCharacterEncoding("utf-8");
            HttpSession session = request.getSession();
            String yzm = (String)session.getAttribute("yzm_session");
            session.removeAttribute("yzm_session");//防止验证码复用
            String yzm_text = request.getParameter("yzm_text");
            if(yzm_text.equalsIgnoreCase(yzm)) {
                //验证码正确,继续判断用户名和密码
                String username = request.getParameter("username");
                String password = request.getParameter("password");
                if(username.equals("yxy")&&password.equals("123456")) {
                    //验证成功,跳转到登录成功界面
                    request.getSession().setAttribute("name", username);
                    request.getRequestDispatcher("/loginSuccess.jsp").forward(request,response);
                }else {
                    //验证失败,返回登录界面,并提示错误信息
                    request.getSession().setAttribute("user_error", "用户名或密码错误!");
                    request.getRequestDispatcher("/index.jsp").forward(request, response);
                }
                }else {
                //验证码错误,返回登录界面,并提示错误信息
                request.getSession().setAttribute("yzm_error", "验证码错误!");
                request.getRequestDispatcher("/index.jsp").forward(request, response);
            }
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request, response);
        }
    
    }
    package servlet;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class exit
     */
    @WebServlet("/exit")
    public class exit extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public exit() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            request.getSession().invalidate();//终结session
            request.getRequestDispatcher("/index.jsp").forward(request, response);
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request, response);
        }
    
    }
  • 相关阅读:
    XCode4 App Store提交小结
    Android Fragment完全解析,关于碎片你所需知道的一切
    [iOS开发系列]根据Debug和Release状态的变化来屏蔽日志输出
    iOS5可能会删除本地文件储存
    iOS5可能会删除本地文件储存
    应用中弹出 WiFi 提示框的方法
    cannot be translated into a null value due to being declared as a primitive type. Consid
    在pom.xml文件中自定义JDK版本+阿里maven镜像修改
    Docker化tomcat 并且使用maven热部署
    使用wget下载JDK8
  • 原文地址:https://www.cnblogs.com/yanzhen108/p/12915226.html
Copyright © 2020-2023  润新知