web jspservlet高级程序设计Word文档格式.docx

上传人:b****2 文档编号:3811577 上传时间:2023-05-02 格式:DOCX 页数:46 大小:541.28KB
下载 相关 举报
web jspservlet高级程序设计Word文档格式.docx_第1页
第1页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第2页
第2页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第3页
第3页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第4页
第4页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第5页
第5页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第6页
第6页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第7页
第7页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第8页
第8页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第9页
第9页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第10页
第10页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第11页
第11页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第12页
第12页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第13页
第13页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第14页
第14页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第15页
第15页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第16页
第16页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第17页
第17页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第18页
第18页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第19页
第19页 / 共46页
web jspservlet高级程序设计Word文档格式.docx_第20页
第20页 / 共46页
亲,该文档总共46页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

web jspservlet高级程序设计Word文档格式.docx

《web jspservlet高级程序设计Word文档格式.docx》由会员分享,可在线阅读,更多相关《web jspservlet高级程序设计Word文档格式.docx(46页珍藏版)》请在冰点文库上搜索。

web jspservlet高级程序设计Word文档格式.docx

一、JSP页面元素

1、静态内容:

---------------------------HTML静态文本

2、指令:

-----------------------------以”<

%@开始”,”以%>

结束”

例如:

‘<

%@includefile=’fileman’%>

3、表达式:

--------------------<

%=表达式%>

4、scriptlet:

------------------<

%代码%>

5、声明:

---------------------------<

%!

函数%>

6、动作:

-------------------------以‘<

jsp:

动作名’开始;

以‘<

/jsp:

动作名’结束

例如:

<

includepage=’filename’/>

7、注释:

·

!

----------------------这是注释---------------------->

(客户断可以看到的)

%------------------这也是注释--------------------%>

(但客户端不能查看到的)

例子:

指令:

%pagecontentType=’text/html’;

charset=’GBK’;

language=’java’;

import=’java·

util·

calendar’%>

声明:

String.getHello(Stringname){

Return‘Hi’+name+’!

}

%>

Jspscriptlet

%

Calendarnow=calendar.getInstancec()

静态内容

html>

head>

/head>

------------------这是注释,是客户端可以看到的------------------>

%----------------这也是注释,但是客户端看不到的---------------%>

body>

<

h1align="

center"

>

JSP页面构成<

/h1>

%=getHello(‘朋友’)%>

%if(now.get(Calendar.AM_PM)==Calendar.AM){%>

早上好!

%}else{%>

下午好!

%}%>

br>

param.name=’str’value=’参数’/>

include>

/body>

/html>

JSP页面

客户端

二、JSP执行过

请求

编译

ajsp.class

ajsp.java

a.jsp

响应

执行

3

转译

1

2

SERVLET

1、转换和编译

JSP

从JSP元素中提取数据转译判断JSP中的错误

为JSP生成一个SERVLET编译

SERVLET

三、开发过程

1、创建JSP工程-------------------2、创建web模块--------------3、创建JSP------------4、调试运行

例子1:

Doubleradius=60;

PrivatdoublegetRadius(){

Returnradius;

PrivatedoublegetDiameter(){

Return(radius*2);

PrivatedoublegetArea(){

Return(3.1415*(radius*2));

PrivatedoublegetCircumference(){

Return(3.1415*radius*2);

圆半径:

%=radius%>

圆直径:

%=getDiameter()%>

圆面积:

%=getArea()%>

圆周长:

%=getCircumference()%>

例子2:

formaction=’circle_area.jsp’method=’post’>

半径:

inputtype=’text’name=’redius’>

<

inputtype=’submit’value=’提交’>

inputtype=’reset’value=’重置’>

/form>

Circle_area.jsp

DoublecircleArea(doubleredius)

{

Return(math.PI*redius*redius);

Stringredius=request.getparameter(‘redius’)

Doublereduss=Double.parsedouble(redus);

Doublearea=cricleArea(rediuss);

半径:

%=reduss%>

的面积:

%=area%>

资料例子1

资料例子2

资料例子3

第三章JSP脚本和指令的使用

一、JSP脚本元素

JSP脚本元素

表达式scriptlet声明

二、表达式的概念

1、表达式是对数据的表示,系统将其作为一个值进行计算和显示

2、表达式的表现形式:

%=Java表达式%>

b>

PI的值:

/b>

%=math.PI%>

100,99中最大值:

%=math.max(100,99)%>

100,99中最小值:

%=math.min(100,99)%>

3+2-5的值:

%=3+2-5%>

(3+2)==5的值:

%=(3+2)==5%>

(3+2)!

=5的值:

%=(3+2)!

=5%>

三、JSPSCRIPTLET的概念

JSPSCRIPTLET就是在JSP页面里嵌入一段Java代码

JSPSCRIPTLET表现形式:

%Java代码%>

例子:

For(inti=1;

i<

10;

i++){

For(intj=0;

j<

=I;

j++){

Out.print(j)

Out.println(‘<

’)

四、Jsp声明的概念

1、jsp声明的概念

JSP声明就是在JSP页面中声明JAVA方法变量等

JSP声明表现形式:

JAVA代码%>

2、将整数转换成带两为小数

//申明一个常量

FinalStringseparatop=’.’;

//声明一个方法

PublicStringcoverts(Stringmoney){

Intindex=money.indexof(separatop);

Stringstr=money;

If(index==-1){

Str=money+’.00’;

Returnstr;

五、JSP指令

JSP指令

Pageincludetaglib

1、指令语法

%@指令名称属性1=‘属性值’,属性2=‘属性值’属性N=‘属性值N’%>

2、page指令用于设置JSP页面的属性

属性:

languageimportisErrorpageerrorpagebuffer

Language------------------定义要使用的脚本语言

Import--------------------将包和方法导入scriptlet

isErrorpage------------表示当前页面能否作为错误页面

errorpage---------------定义处理异常的JSP页面

buffer--------------------设置用来存储客户端请求的缓冲区的大小

%@

Pagelanguage=’java’import=’java.util*’buffer=’8kb’errorpage=’errorjsp’isErrorpage=’false’

---------------------page指令属性

3、include指令是用于将在运行是将HTML文件或JSP页面嵌入到另一个JSP页面

include语法:

%@includefile=’文件名’%>

例子:

%@includefile=’/test.html’%>

还可以放在html上面

4、taglib指令可以让jsp页面使用标签

语法:

%@tagliburi=’标签库表述符文件’prefix=‘前缀名’%>

%@tagliburi=’/mytaglib.tld’prefix=’mytags’%>

六、例子

例子1:

将整数转换成两为小数

Stringformats(doubleb){

Nummberformatnf=numberformat.getinstance();

Nf.setMaxmumfractimwigits

(2);

Nf.setMinimumfractionwigits

(2);

Returnnf.format(b)

%=formats(6)%>

例子2:

//格式化日期的输出

StringformatDAte(dated){

//yy年MM月dd日hh时mm分ss秒

simpleDateformatsdf=newsimpleDateformat(yy年MM月dd日hh时mm分ss秒);

StringdateString=sdf.format(b)

Returndatestring;

%=formatDate(newdate())%>

第四章JSP隐式对象

一、JSP隐式对象的定义

1、定义:

jsp隐式对象是web容器加载的一组类,它不用‘new’去获取实例,而是可以直接在jsp页面使用的对象

隐式对象

输入\出对象作用域通信对象servlet对象错误对象

Requestsessionpage

Resporseappticationexception

Outpagecontextconfig

二、request对象常用方法

Stringgetparameter(Stringname)

根据表单组件名称获取请求页面提交数据

Stringgetparametervalues(Stringname)

获取页面请求中一个表单组件对应多个值是的用户的请求数据

Stringname=request.getparameter(‘name’)

Stringchannels=request.getparametervalues(“channel”)

三、response对象常用方法

voidsetcontentType(Stringname)

设置作为响应生成的内容的类型和字符编码

voidsendredirect(Stringname)

发送一个响应给浏览器,指示起应请求另一个URL

Response.setcontentType(‘text/html,charse=GBK’);

Response.sendredirect(‘response.jsp’);

四、out对象

javax.servLet.jsp.writer类型的实例

使用write(),print()和println()方法

Out.print(“欢迎来到jsp;

隐式对象”);

五、作用域通信对象

隐式对象的作用域包括page、request、session、和application

作用于通信对象包括:

session、application和pagecontext

六、session对象

web服务器为单个用户发送的多个请求创建的会话

作用:

存储有关用户会话的所有信息

javax、servlet、http、httpsession接口的实例

session对象最常用的方法

1、·

voidsetAttribute(Stringname,objectvalue)

以键/值的方式,将一个对象的值存放到session中

2、·

voidgetAttribute(Stringname)

根据名称去获取session中存放对象的值

Session.setAttribute(‘name’,’admin’)

If(session.getAttribute(name)!

=null){

Stringname=(String)session.getAttribute(‘name’);

七、application它与session同理

javax.servLet.servLetcontext接口实例

%application.setAttribute(‘chartrecord’,’hihi’)%>

%if(application.getAttribute(‘chartrecord’)!

Stringchartrecord=(String)application.getAttribute(‘chartrecord’)

八、pagecontext同上

九、servlet对象

1、jsp引擎为每个jsp生成一个servlet

servlet对象提供了访问servlet信息的方法和变量

servlet对象包括:

page和config

十、page对象

使用page对象可以访问servlet类的所有变量和方法

十一、config对象

提供了检索servlet初始化参数方法

十二、Exception对象

Exception对象:

1用于处理jsp页面中的错误;

2用于访问执行jsp的过程中引发的异常

3是java.lang.throwable类的实例

十三、例子

%@pageisErrorpage=’true’%>

h1>

隐式对象异常<

以检测到以下错误<

%=exception%>

%exception.rintstackTrance(out)%>

例子2:

处理错误

If(exception!

Out.write(“\n发生错误\n”);

}else{

Out.write(“\n你已访问此页面,但是没有可用的错误信息\n”)

第五章javaBean和jsp的标准动作

一、javaBean的优点

1、javaBean的优点

可重用组件

可在多个应用程序中使用

可以跨平台

2、用途

将javaBean嵌入jsp页面

设置和获取javaBean的属性

将用户请求转发给其他页面

将其它页面的内容嵌入当前页面

useBeanid=’BeanID’class=’MyBean’scope=’page’>

二、UseBean动作范围指定javaBean在jsp页面中的可用性范围

PageBean

只能在使用页面是使用,当加载新页面时,将其销毁

RequestBean

在用户对其发出请求的存在

SessionBean

一直存在于会话中,知道其终止或被删除为止

Applicationbean

在整个应用程序中均可使用

Get()方法和set()方法用于访问javaBean的属性

Get()方法javaBean的属性set()方法

 

定义公有方法get()方法返回值

定义公有方法set方法给属性赋值

Importjava.io.*;

PublicclassMyBean{

PrivateStringname;

PublicMyBean(){}

PublicStringgetName(){

Returnname;

PublicvoidsetName(StringMyName){

This.name=MyName;

三、jsp的标准动作

1、jsp的标准动作

useBean>

<

getproperty>

setproperty>

forward>

2、setproperty动作

useBeanid=’BeanID’class=’MyBean’scope=’session’/>

setpropertyname=’BeanID’property=’name’value=’示例’/>

getpropertyname=’BeanID’property=’name’/>

3、示例:

在jsp中使用javaBean

useBeanid=’BeanId’class=’example5.sinpleseem’scope=’application’/>

setpropertyname=’BeanId’property=’age’value=’25’/>

姓名:

getpropertyname=’BeanId’propery=’name’/>

年龄:

getpropertyname=’BeanId’property=’age’/>

//<

jsp;

forwardpage=’second.jsp’/>

四、include动作

<

includepage=’otherPage.jsp’flush=’true’/>

五、例子

第六章jsp表达是语言

一、EL为表达式语言

1、EL用于以下情况

静态文体

标准标签和自定义标签

table>

tr>

td>

逻辑运算<

/td>

EL表达式<

Result<

/tr>

与<

${‘${’}trueandtrue<

${trueandtrue}<

${‘${’}true&

&

false}<

${true&

&

false}<

或<

${‘${’}trueorfalse}<

${trueorfalse}<

${‘${’}true||false}<

${true||false}<

非<

${‘${’}nottrue}<

${nottrue}<

${‘${’}!

${!

/table>

inputtype=’text’name=’num’value=’${param[‘num’]}’>

例子3:

pageContext.setAttribute(‘color’,’#FFFFCC’)

bodybgcolor=’${pageScope.color}’>

变化的背景色,<

二、禁止EL计算的语法为

1、禁止EL计算的语法为:

%@pageisElIgnored=’false/true’%>

%@pageisELIgnored=false/true%>

false/true

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 动态背景

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2