视图的数据修改,表中也修改
引用工具类用<%@ 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 登陆注册页面的更多相关文章

  1. javaWeb登录注册页面

    简单的登陆注册页面 1.配置JDBC驱动连接数据库 2. 配置struts2框架 3. 利用1 2完成登录页面, 注意做到不耦合,即servlet Api和控制器完全脱离) 4. 利用1 2 制作注册 ...

  2. git冲突解决、线上分支合并、luffy项目后台登陆注册页面分析引入

    今日内容概要 git冲突解决 线上分支合并 登陆注册页面(引入) 手机号是否存在接口 腾讯云短信申请 内容详细 1.git冲突解决 1.1 多人在同一分支开发,出现冲突 # 先将前端项目也做上传到 g ...

  3. java 24 - 11 GUI之制作登陆注册页面

    简单说说,懒得发了... 步骤: A:首先写出登陆注册需要用到类以及代码(IO流) B:然后创建登陆窗口和注册窗口 C:各个监听事件: a:登录窗口 1.重置:把2个文本框的内容全部清空 2.注册:关 ...

  4. javaweb实现注册页面(数据库连接以及ajax验证)

    先放效果图 可实现js实时验证        可实现ajax实时验证注册信息是否存在   页面实现要求 1登录账号:要求由6到12位字母.数字.下划线组成,只有字母可以开头:(1分) 2登录密码:要求 ...

  5. html+css+js实现简单登陆注册页面

    先看一下最终效果,登陆和注册 背景图片: 附源码: login.html <!DOCTYPE html> <html lang="en"> <head ...

  6. PHP数据库登陆注册简单做法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. 微信小程序常见两种登陆注册方式(一)

    普通登录注册以及用户授权登陆 普通登陆注册 概述 此功能的实现简单的借助了微信小程序的云开发,具体在哪里使用,我会标出来.对于用户名.账号.密码都做了简单的校验.主要练手功能的实现,样式只做了简单的编 ...

  8. JavaWeb 例子 JDBC+JSP登陆注册留言板

    注册页面: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...

  9. Android笔记-4-实现登陆页面并跳转和简单的注册页面

    实现登陆页面并跳转和简单的注册页面   首先我们来看看布局的xml代码 login.xml <span style="font-family:Arial;font-size:18px; ...

随机推荐

  1. win10下安装python

    1. 在官网下载python:https://www.python.org/ftp/python/3.5.2/python-3.5.2-amd64.exe 这里下载的是3.5.2版. 2. 双击exe ...

  2. 谈谈webpack 的优势

    其优势主要可以归类为如下几个: 1. webpack 是以 commonJS 的形式来书写脚本滴,但对 AMD/CMD 的支持也很全面,方便旧项目进行代码迁移. 2. 能被模块化的不仅仅是 JS 了. ...

  3. 详解Linux chgrp和chown命令的用法

    Linux chgrp和chown命令是管理员的常用命令,对于初学Linux系统管理的人来说,这对Linux chgrp和chown命令具体的用法这里做一介绍. Linux chgrp命令 功能:改变 ...

  4. tomcat一个端口配置多个项目

    在server.xml中增加host节点 <Host name="localhost" appBase="webapps" <!--这是默认的--- ...

  5. spring boot 打war包部署,打jar包

    官方文档:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable- ...

  6. Java代码优化六大原则

    单一职责 代码优化第一步,单一职责原则 (Single Responsibility Principle).对于一个Java类,应该仅有一个引起它变化的原因,也就是说,一个类中,应该是一组相关性很高的 ...

  7. Java List Remove时要注意的细节

    1.如果你是在遍历的时候去remove一个对象 for(int i = 0, length = list.size(); i<length; i++){} 这种遍历需要每次remove时,对i- ...

  8. 2.1 insertion sort 《算法导论》答案

    2.1 insertion sort <算法导论>答案 答案索引帖 2.1-1 Using Figure 2.2 as a model, illustrate the operation ...

  9. Ubuntu14.04设置开机自启动程序

    启动应用程序可以帮助我们选择开机启动项.但是在Ubuntu14.04通过Dash输入startup 找不到启动应用程序了,可以通过在控制台输入以下内容: gnome-session-propertie ...

  10. Android - AIDL 使用

    AIDL(Android Interface Definition Language) 程序员可以利用AIDL自定义编程接口,在客户端和服务端之间实现进程间通信(IPC).在Android平台上,一个 ...