javaweb登录注册页面;

Posted 如果能够

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;width: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;width: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;width: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;width: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;width: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>





























































































































以上是关于javaweb登录注册页面;的主要内容,如果未能解决你的问题,请参考以下文章

JavaWeb_用户登录注册模板

怎么用java-web获得当前登录此页面人的列表

web前端如何做注册页面

JavaWeb-SpringBoot_使用H2数据库实现用户注册登录

基于javaweb的web资源库项目——登录功能demo

基于javaweb的web资源库项目——登录功能demo