zoukankan      html  css  js  c++  java
  • javaweb登录注册页面;

    初学javaweb,第一个要做的项目就是登陆注册页面,被这两个页面折磨了两天,终于写出来了,相信也会有许多初学者会面临着写这个页面的问题,给大家提供一段代码,仅供参考。

    登录页面;

    <form action="in.jsp" method="post">
    <input type="hidden" name="hidden" value="deng">
    <table>
    <tr>
    <td width="150px" height="50px">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;账号
    </td>
    <td width="300px" height="50px">
    <input type="text" placeholder="请输入账号" style="height:30px;250px;" name="username">
    </td>
    </tr>
    <tr>
    <td>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密码
    </td>
    <td>
    <input type="password" placeholder="请输入密码" style="height:30px;250px;" name="password">
    </td>
    </tr>
    </table>
    <div id="button">
    <input type="submit" value="登录">
    </form>
    <a href="zhuce.jsp">去注册</a>

    注册页面;

    <form action="in.jsp" method="post">
    <input type="hidden" name="hidden" value="zhu">
    <table>
    <tr>
    <td width="150px" height="50px">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;账号
    </td>
    <td width="300px" height="50px">
    <input type="text" placeholder="请输入账号" style="height:30px;250px;" name="username">
    </td>
    </tr>
    <tr>
    <td>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密码
    </td>
    <td>
    <input type="password" placeholder="请输入密码" style="height:30px;250px;" name="password">
    </td>
    </tr>
    <tr>
    <td>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;确认密码
    </td>
    <td>
    <input type="password" placeholder="请再次输入密码" style="height:30px;250px;" name="password0">
    </td>
    </tr>
    </table>
    <div id="button">
    <input type="submit" value="注册">
    </form>

    中间需要跳转的in.jsp;

    <%
    request.setCharacterEncoding("utf-8");
    String hidd=request.getParameter("hidden");
    if("deng".equals(hidd)){
    String username=request.getParameter("username");
    String password =request.getParameter("password");

    if(username!=null&&username.trim().length()>0){
    Object oo=application.getAttribute(username);
    if(oo==null){
    response.sendRedirect("java.jsp?code=5");
    }
    else{
    String userinfo=(String)oo;
    if(password.equals(userinfo.split(",")[1])){
    response.sendRedirect("pinglun.jsp");
    }
    else{
    response.sendRedirect("java.jsp?code=6");
    }
    }
    }
    else{
    response.sendRedirect("java.jsp?code=4");
    }
    }
    if("zhu".equals(hidd)){
    String username=request.getParameter("username");
    String password=request.getParameter("password");
    String password0=request.getParameter("password0");
    Object obj=application.getAttribute("username");
    if(obj==null){
    if(password.equals(password0)){
    application.setAttribute(username, username+","+password);
    response.sendRedirect("java.jsp?code=2");
    }
    else{
    response.sendRedirect("java.jsp?code=3");
    }
    }
    else{
    response.sendRedirect("java.jsp?code=1");
    }
    }

    %>

    java.jsp;

    <%
    String code=request.getParameter("code");
    if(code.equals("1")){
    out.print("<h5>该用户已经存在 </h5>");
    }
    if(code.equals("2")){
    out.print("<h5>注册成功 </h5>");
    }
    if(code.equals("3")){
    out.print("<h5>两次输入密码不同 </h5>");
    }
    if(code.equals("4")){
    out.print("<h5>请输入用户名 </h5>");
    }
    if(code.equals("5")){
    out.print("<h5>请先前往注册 </h5>");
    }
    if(code.equals("6")){
    out.print("<h5>密码错误! </h5>");
    }

    %>
    <a href="denglu.jsp">登录</a>
    <a href="zhuce.jsp">注册</a>

  • 相关阅读:
    tomcat最大线程数的设置(转)
    webService接口大全
    实用工具网站汇总
    Linux常用指令(待补充)
    svn的使用总结(待补充)
    养生
    nodejs知识结构
    NVM node版本管理工具的安装和使用
    MongoDB安装和MongoChef可视化管理工具的使用
    JavaScript模块化编程(三)
  • 原文地址:https://www.cnblogs.com/hljj/p/7060150.html
Copyright © 2011-2022 走看看