Jsp登录注册页面代码(求jsp简单的登陆跳转注册页面)

2024-05-07 02:30:06 :56

jsp登录注册页面代码(求jsp简单的登陆跳转注册页面)

这篇文章给大家聊聊关于jsp登录注册页面代码,以及求jsp简单的登陆跳转注册页面对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

本文目录

求jsp简单的登陆跳转注册页面

登陆页:《%@ page language="java" pageEncoding="GB18030"%》《head》《/head》《body》 《form action="login_success.jsp" method="post"》 用户名: 《input type="text" name="username" /》 《br》 密 码 《input type="password" name="password" /》 《br》 《input type="submit" name="Submit" value="登陆" /》 《input type="reset" name="cancelButton" value="取消" /》 《/form》《/body》登陆成功页:《%@ page language="java" pageEncoding="GB18030"%》《head》《/head》《body》 《% String name = request.getParameter("username"); String pwd = request.getParameter("password"); if ("hello".equals(name.trim()) && "word".equals(pwd.trim())) { %》 《h1》 登陆成功: 《%=name%》《/h1》 《% } else { %》 《h1》 登录失败: 《/h1》 《br》 三秒后跳到注册页面: 《% response.setHeader("refresh", "3;url=regiest.jsp"); %》 《% } %》《/body》注册页:《%@ page language="java" pageEncoding="GB18030"%》《head》《/head》《body》 《form action="regiest_success.jsp" method="post"》 用户名: 《input type="text" name="username" /》 《br》 密 码 《input type="password" name="password" /》 《br》 确认密 码 《input type="password" name="password2" /》 《br》 《input type="submit" name="Submit" value="注册" /》 《input type="reset" name="cancelButton" value="取消" /》 《/form》《/body》注册成功页:《%@ page language="java" pageEncoding="GB18030"%》《head》《/head》《body》 《% String name = request.getParameter("username"); String pwd = request.getParameter("password"); String pwd2 = request.getParameter("password2"); if (null == name || "".equals(name)) { out.print("用户名不能为空!!"); return; } if (null == pwd || "".equals(pwd)) { out.print("密码不能为空!!"); return; } if (null == pwd2 || "".equals(pwd2)) { out.print("确认密码不能为空!!"); return; } if (!pwd.equals(pwd2)) { out.println("两次密码不正确!"); return; } response.sendRedirect("login.jsp"); %》《/body》

如何在jsp页面上实现点击注册按钮,弹出一个窗体来注册(类似于百度贴吧的登录和注册),求详细代码和注释

jsp中的注册弹出新窗口是通过window.open一个新页面来实现的。页面register.jsp代码如下:《%@ page contentType="text/html; charset=gb2312" language="java" import="cn.wy.Pet.User" errorPage="" %》***隐藏网址******隐藏网址***《head》***隐藏网址***《title》会员注册例子讲解《/title》《style type="text/css"》《!--.STYLE1 { color: #FF0000; font-weight: bold;}.STYLE2 {color: #FF0000}.STYLE3 { font-size: 18px; font-weight: bold;}--》《/style》《/head》《body style="font-size:12px"》《form id="form1" name="form1" method="post" action="《%=actionStr%》reg"》 《p align="center"》《br /》 《span class="STYLE3"》用户注册《/span》《/p》 《table width="582" height="302" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#BCACD2"》 《tr》 《td width="80" align="right"》用户名:《/td》 《td width="496" align="left"》《input name="userName" type="text" id="userName" size="16" maxlength="16" /》 《span class="STYLE1"》*《/span》 3~16位字母或者数字(如:8hack)《/td》 《/tr》 《tr》 《td align="right"》密码:《/td》 《td align="left"》《input name="password1" type="text" id="password1" size="16" maxlength="16" /》 《span class="STYLE1"》* 《/span》 3~16位字母或者数字(如:abc123)《/td》 《/tr》 《tr》 《td align="right"》确认密码:《/td》 《td align="left"》《input name="password2" type="text" id="password2" size="16" maxlength="16" /》 《span class="STYLE1"》*《/span》 必须和上面输入的密码相同《/td》 《/tr》 《tr》 《td align="right"》电子邮件:《/td》 《td align="left"》《input name="email" type="text" id="email" maxlength="20" /》 《span class="STYLE1"》*《/span》 找回密码和联系用(如:8hack@163.com)《/td》 《/tr》 《tr》 《td align="right"》联系电话:《/td》 《td align="left"》《input name="tel" type="text" id="tel" size="20" maxlength="20" /》 如(0871-8888888,13888853113)《/td》 《/tr》 《tr》 《td align="right"》联系地址:《/td》 《td align="left"》《input name="address" type="text" id="address" maxlength="50" /》《/td》 《/tr》 《td height="40" colspan="2" align="center"》《input type="submit" name="Submit" value="确认注册" /》 《input type="reset" name="Submit2" value="重新填写" /》《/td》 《/tr》 《/table》《/form》《/body》《/html》后台servlet的处理:public class reg extends HttpServlet{ public reg() { } protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out; DBConnection dbc=null; String userName; String psd; String email; String tel; String address; int popedom; response.setContentType("text/html;charset=UTF-8"); out = response.getWriter(); try{ dbc = new DBConnection(); PreparedStatement ps = null; userName = request.getParameter("userName"); psd = login.encrypt(request.getParameter("password1").toString()); email = request.getParameter("email"); tel = request.getParameter("tel"); address = request.getParameter("address"); popedom = Integer.parseInt(request.getParameter("popedom")); if (userName != null && psd != null && email != null) { ps = dbc.getCon().prepareStatement("insert into (UName,Upass,UEmail,UTel,UAddress,UPopedom) values(?,?,?,?,?,?)"); ps.setString(1, userName); ps.setString(2, psd); ps.setString(3, email); ps.setString(4, tel); ps.setString(5, address); ps.setInt(6, popedom); ps.execute(); System.out.print("新用户注册:" + request.getParameter("userName") + " "); out.print("《script》alert(’恭喜您:注册成功!现已经登录到网站!’);history.go(-1)《/script》"); } if (dbc != null) dbc.dbClose(); } catch(SQLException ex) { out.print("《script》alert(’注册失败!数据库连接错误!’);history.go(-1)《/script》"); ex.printStackTrace(); if (dbc != null) dbc.dbClose(); } }}

OK,关于jsp登录注册页面代码和求jsp简单的登陆跳转注册页面的内容到此结束了,希望对大家有所帮助。

jsp登录注册页面代码(求jsp简单的登陆跳转注册页面)

本文编辑:admin
Copyright © 2022 All Rights Reserved 威海上格软件有限公司 版权所有

鲁ICP备20007704号

Thanks for visiting my site.