概述
该技术已过时
jsp 已经过时,是因为代码杂糅在一起,没有做到完美的分离.不利于后期的维护
java bean 过时的原因在于面条代码的存在,即,各种代码杂乱的糅合在一起.
特点
组件式编程 步骤封装成为组件,需要那个的时候,直接调用组件即可.增加复用性
标准目录结构
WEB-INF
该目录为web目录中最安全的文件夹.保存各种类,第三方jar包,配置文件.
WEB-XML
web部署的描述符
classes
保存所有hacabean
lib
第上方jar包
tags
保存所有标签文件
jsp
保存jsp文件
css
保存样式表文件
images
保存图片文件
page导入JavaBean
package demo;
public class demo {
public String name;
public String age;
public demo(){
}
public void setName(String name){
this.name = name;
}
public void setAge(String age){
this.age = age;
}
public String getName(){
return this.name;
}
public String getAge(){
return this.age;
}
}
Created by IntelliJ IDEA.
User: ming
Date: 19-3-14
Time: 下午9:19
To change this template use File | Settings | File Templates.
--%>
Titledemo demo = new demo();
demo.setAge("12");
demo.setName("ming");
%>
JavaBean与表单
同jsp 直接传参即可
jsp:useBean指令
使用jsp:useBean指令可以直接调用类
Created by IntelliJ IDEA.
User: ming
Date: 19-3-14
Time: 下午9:19
To change this template use File | Settings | File Templates.
--%>
Titledemo.setName("ming");
demo.setAge("12");
%>
JavaBean范围
使用scope属性标记范围 当为post的时候,表示为只在本页生效. 当为request的时候,表示在一次页面跳转,不会重新实例化对象 当为session,表示对象的生命周期为整个会话 当为application的时候,表示为所有用户共同拥有这个对象.即为单例模式
栗子
注册验证
Created by IntelliJ IDEA.
User: ming
Date: 19-3-15
Time: 上午12:53
To change this template use File | Settings | File Templates.
--%>
用户注册页用户名"/>
年龄"/>
E-Mail"/>
Created by IntelliJ IDEA.
User: ming
Date: 19-3-15
Time: 上午2:04
To change this template use File | Settings | File Templates.
--%>
Title用户名
年龄
Created by IntelliJ IDEA.
User: ming
Date: 19-3-15
Time: 上午12:55
To change this template use File | Settings | File Templates.
--%>
信息验证中// 进行验证
if(reg.isVaildate()){
%>
}else{
%>
}
%>