四大指令元素
1.页面指令
页面指令用来定义jsp文件中的全局属性。一个页面可以包含多个页面指令
1
16%>
2.include指令
1
该包含为静态包含,file1包含file2,则将file2的代码插入至file1的指定位置作为一个jspfile,然后再编译。两个文件中变量会复用。
3.taglib
我不懂
4.表达式语言
参考其他人的吧
三大脚本元素
1.声明
声明是一段java代码,可以用来定义类或方法
1
2 classStudent{3 private intid;4 privateString name;5
6 public Student(){}7
8 public Student(intid, String name){9 this.id =id;10 this.name =name;11 }12
13 publicString getName(){14 returnname;15 }16
17 public intgetId(){18 returnid;19 }20 }21 %>
2.scriplets
jsp页面处理请求时执行的代码,可以产生输出,也可以时流程控制语句
out.println(s1.getName());%>
2.scriplets
八大动作元素
1.param
jsp:param操作被用来以“名-值”对的形式为其他标签提供附加信息,通常与组合使用。
2.include
jsp:include操作允许在请求时间内,让现成的jsp页面中包含静态或动态资源。被包含的对象只有对jsp writer对象的访问权,并且不能设置头或cookie。如果页面输出是缓冲的,那么缓冲区的刷新要优于包含的刷新。
实例1.
>
©2012Slowalker Lee
Insert title here
实例2.
主页面
pageEncoding="ISO-8859-1"%>
Insert title here运行结果:
the parameter is slowalker
3.
将请求转发到另一个页面。
验证登录的例子。
confirmLogIn.jsp
Insert title hereuser name: | |
password : | |
int a = 0;try{
a= Integer.parseInt(request.getParameter("passwd"));
}catch(NumberFormatException e){}if (request.getParameter("name").equals("slowalker") && (a == 123)){%>
//账户密码正确,跳转至成功界面
//账号密码不正确,跳转至登录界面重新填写账号密码
Insert title heresuccess
4.
id:一个大小写相关的名字,在所定义的范围中确认Bean的变量
/ page:能够在包含标签的JSP文件以及此文件中的所有静态包含文件使用Bean
| request:在请求范围内使用有效 request.getAttribute(name) name是bean实例化的名字
scope:此对象可使用的范围 { session.getValues(name) name是bean实例化的名字
| session:从创建Bean开始,就可以在session有效范围内使用这个Bean,这个Bean对JSP来说是共享的。
\ application:从创建Bean开始,就可以在aplication有效范围内使用这个Bean,这个Bean对JSP来说是共享的。
application对象在应用服务器启动时创建,直至服务器关闭。
application.getAttribute(name) name是bean实例化的名字
/ class="className" bean的类路径和类名,这个class不能是抽象的。必须有一个公用的无参构造器。
| class="className" type="typeName" 使用instantiate方法从一个class中实例化一个Bean,同时可以指定Bean类型
typeSpec {
| beanName="beanName" type="typeName"
\ type="typeName"
1 packagecom.servlet.test;2
3 public classTestBean {4 publicString userName;5 publicString password;6 public intage;7
8 publicTestBean() {} //Bean中必须有一个无参构造器9
10 publicString getUserName() {11 returnuserName;12 }13
14 public voidsetUserName(String userName) {15 this.userName =userName;16 }17
18 publicString getPassword() {19 returnpassword;20 }21
22 public voidsetPassword(String password) {23 this.password =password;24 }25
26 public intgetAge() {27 returnage;28 }29
30 public void setAge(intage) {31 this.age =age;32 }33
34
35 }
1
2
3
4
5
6
Insert title here7
8
9
10
11
12
姓名:13
14
15
密码:16
17
18
年龄:19
20
21
22
23
24
>25
26
1
2 pageEncoding="UTF-8"%>
3
4
5 //
6
7
8
9
Insert title here10
11
12 注册成功
13
14 使用Bean的属性方法:
15 用户名:
16 密码:
17 年龄: //此处的用户名 密码 年龄均为之前填写的值
18
19
20
关于Bean的猜想:调用一个包含Bean的页面时, 此句实例化出一个名为user的TestBean对象
没有搞懂useBean的执行过程
5.setProperty
6.getProperty
7.plugin
8.fallback