javaweb 登陆注册页面
视图的数据修改,表中也修改
引用工具类用<%@ page import=""%>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
引入包可以一条一条分着写,也可以在一条内直接用逗号隔开写
<%@ page import="java.util.Date,java.text.SimpleDateFormat " %>
application.getAttribute存的是键值对。。。
强转
object getattribute(string name):获取指定的属性
enumeration getAttributenames():获取所有的属性的名字组成的enumeration
removeattribute(string name):移除指定的属性
void setattribute(string name,object o):设置属性
pagecontext,request,session,application,都有这些方法,成为作用域对象
pagecontext:属性的作用范围仅限于当前页面
request:仅限于同一个请求
session:仅限于一次回话,浏览器打开直到关闭称之为一个回话(回话不失效)
application:属性的作用范围限于当前web应用,是范围最大的,只要在一处设置属性,在其他各处都可以获取到
登陆注册实例
首页页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<% //防止用户不登陆进入首页
Object obj=session.getAttribute("currentUser");
if(obj==null){
response.sendRedirect("login.jsp");
} %> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>这是首页</h1>
<a href="login.jsp"><input type="button" name="login" value="登陆"/></a> <br>
<a href="resist.jsp"><input type="button" name="resist" value="注册"/></a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>这是注册页面</h1>
<form action="operation.jsp" method="post" >
<input type="text" name="username" placeholder="请输入用户名"/><br>
<input type="text" name="password" placeholder="请输入密码"/><br>
<input type="text" name="password1" placeholder="请再次输入密码"/><br>
<a href="login.jsp"><input type="submit" value="注册"/></a>
</form> </body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="textloginresist.User" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String username=request.getParameter("username");
String password=request.getParameter("password");
String password1=request.getParameter("password1"); if(password.equals(password1)){
Object o=application.getAttribute(username);
if(o!=null){
out.print("用户已经存在");
}else{
User u = new User();
u.setUsername(username);
u.setPassword(password);
application.setAttribute(username, u);
}
}else{
out.print("两次输入不一致");
}
out.print("注册成功");
out.print("<a href='login.jsp'>跳转页面</a>");
%>
</body>
</html>
登陆:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>这是登陆页面</h1>
<form action="operationlogin.jsp" method="post" >
<input type="text" name="username" placeholder="请输入用户名"/><br>
<input type="text" name="password" placeholder="请输入密码"/><br>
<a href="index.jsp"><input type="submit" value="登陆"/></a>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="textloginresist.User" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% String username=request.getParameter("username");
String password=request.getParameter("password"); if(username!=null){
User u = (User)application.getAttribute(username);
if(username.equals(u.getUsername())){
if(password.equals(u.getPassword())){
session.setAttribute("currentUser", u);//防止用户不登陆进入首页
response.sendRedirect("index.jsp");
}else{
out.print("密码错误");
}
}else {
out.print("用户不存在!");
out.print("<a href='login.jsp'>跳转页面</a>");
}
}else{
out.print("输入有误");
}
%>
</body>
</html>
javaweb 登陆注册页面的更多相关文章
- javaWeb登录注册页面
简单的登陆注册页面 1.配置JDBC驱动连接数据库 2. 配置struts2框架 3. 利用1 2完成登录页面, 注意做到不耦合,即servlet Api和控制器完全脱离) 4. 利用1 2 制作注册 ...
- git冲突解决、线上分支合并、luffy项目后台登陆注册页面分析引入
今日内容概要 git冲突解决 线上分支合并 登陆注册页面(引入) 手机号是否存在接口 腾讯云短信申请 内容详细 1.git冲突解决 1.1 多人在同一分支开发,出现冲突 # 先将前端项目也做上传到 g ...
- java 24 - 11 GUI之制作登陆注册页面
简单说说,懒得发了... 步骤: A:首先写出登陆注册需要用到类以及代码(IO流) B:然后创建登陆窗口和注册窗口 C:各个监听事件: a:登录窗口 1.重置:把2个文本框的内容全部清空 2.注册:关 ...
- javaweb实现注册页面(数据库连接以及ajax验证)
先放效果图 可实现js实时验证 可实现ajax实时验证注册信息是否存在 页面实现要求 1登录账号:要求由6到12位字母.数字.下划线组成,只有字母可以开头:(1分) 2登录密码:要求 ...
- html+css+js实现简单登陆注册页面
先看一下最终效果,登陆和注册 背景图片: 附源码: login.html <!DOCTYPE html> <html lang="en"> <head ...
- PHP数据库登陆注册简单做法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 微信小程序常见两种登陆注册方式(一)
普通登录注册以及用户授权登陆 普通登陆注册 概述 此功能的实现简单的借助了微信小程序的云开发,具体在哪里使用,我会标出来.对于用户名.账号.密码都做了简单的校验.主要练手功能的实现,样式只做了简单的编 ...
- JavaWeb 例子 JDBC+JSP登陆注册留言板
注册页面: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...
- Android笔记-4-实现登陆页面并跳转和简单的注册页面
实现登陆页面并跳转和简单的注册页面 首先我们来看看布局的xml代码 login.xml <span style="font-family:Arial;font-size:18px; ...
随机推荐
- Linux 重启和关机命令
shutdown -r 05:30 在凌晨五点30分关机 shutdown -r 05:30 & 后台执行 shutdown -c 取消前一个关机命令 ...
- 通用JSONHelp 的通用的封装
1. 最近项目已经上线了 ,闲暇了几天 想将JSON 的序列化 以及反序列化进行重新的封装一下本人定义为JSONHelp,虽然Microsoft 已经做的很好了.但是我想封装一套为自己开发的项目使用 ...
- Android之ListView优化
关于ListView几个方面的优化: ListView的大小设定固定值; 复用convertView, 使用ViewHolder提高在容器中查找组件的效率; 使用分页加载; 快速滚动时, item不显 ...
- 51nod_1639:绑鞋带
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1639 #include <bits/stdc++.h& ...
- 使用xcrun打包iOS应用
使用xcrun打包iOS应用 通常打包采用xcodebuild和xcrun两个命令,xcodebuild负责编译,xcrun负责将app打成ipa. XCode 默认编译出来的是appName.a ...
- (转)sizeof
数据类型的大小(即所占字节数)以及能够表示的数据范围是与编译器和硬件平台有关的."float.h"头文件(如vc6.0,在include目录下)通常定义了基本数据类型能够表示的数据 ...
- Framework7 索引列表插件的问题
前言 Framework7 作为移动端的开发框架的优良之处已经无需多言.现在已经有了 React 和 Vue 版本,之前在项目中用过 F7 + vue 的开发方式,无论是效率还是产出都近乎完美.有时间 ...
- POJ 3669 Meteor Shower (BFS+预处理)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- FarmCraft[POI2014]
题目描述 In a village called Byteville, there are houses connected with N-1 roads. For each pair of ho ...
- Hadoop 新生报道(三) hadoop基础概念
一.NameNode,SeconderyNamenode,DataNode NameNode,DataNode,SeconderyNamenode都是进程,运行在节点上. 1.NameNode:had ...