JavaEE复习大纲.docx

上传人:b****5 文档编号:6009446 上传时间:2023-01-02 格式:DOCX 页数:15 大小:20.20KB
下载 相关 举报
JavaEE复习大纲.docx_第1页
第1页 / 共15页
JavaEE复习大纲.docx_第2页
第2页 / 共15页
JavaEE复习大纲.docx_第3页
第3页 / 共15页
JavaEE复习大纲.docx_第4页
第4页 / 共15页
JavaEE复习大纲.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

JavaEE复习大纲.docx

《JavaEE复习大纲.docx》由会员分享,可在线阅读,更多相关《JavaEE复习大纲.docx(15页珍藏版)》请在冰豆网上搜索。

JavaEE复习大纲.docx

JavaEE复习大纲

一、Web.xml文件中的标记

1、Servlet的配置标记、初始化参数配置

initServlet

com.initServlet

filePath

temp

initServlet

/url

Servlet中获取初始化参数语句

1)Stringpath=getInitParameter(“filePath”);

2)ServletConfigconfig=this.getServletConfig();

Stringpath=config.getInitParameter(“filePath”);

2、Filter的配置标记

TimeTrackFilter

com.servlet.TimeTrackfilter

TimeTrackFilter

/Main

3、Web应用的上下文初始化参数配置

url

.diner

在Servlet中获取参数的语句

1)ServletContextcontext=this.etServletContext();

Stringurl=context.getInitParameter(“url”);

2)ServletConfigconfig=getServletConfig();

ServletContextcontext=config.getServletContext();

Stringurl=context.getInitParameter(“url”);

4、在web.xml文件中指定监听器

com.servlet.CounterListener

二、Servlet

1)Servlet周期

1、生命周期的方法:

●init()方法:

初始化方法,执行一次

●service()方法:

接收请求时调用

●doGet()方法:

接收Get请求时被service()方法调用

●doPost()方法:

接收Post请求时被service()方法调用

2、Get请求和Post请求

表单时是post请求

表单或者默认是Get请求

超链接发请求是Get请求

2)目录

项目目录结构

WEB-INF目录下存放的文件

Web.xml

classes文件夹

lib文件夹

3)请求对象参考ServletAPI

1、获得请求参数的方法

2、获得一个表单参数的单个值的方法

3、获得一个表单参数的多个值的方法

4、获得请求头信息的方法(两个)

4)响应对象参考ServletAPI

1、设置响应类型的方法:

setContentType()

响应结果为HTML:

response.setContentType(“text/html”)

响应结果为Word:

response.setContentType(“applicationt/msword”)

响应结果为excel:

response.setContentType(“applicationt/vnd.ms-excel”)

响应结果为pdf:

response.setContentType(“applicationt/pdf”)

2、设置响应编码:

response.setCharacterEncoding()

5)监听器

1、ServletContext监听器的方法调用

Web应用初始化的时候:

contextInitialized()

Web应用结束的时候:

contextDestroyed()

2、与HTTP会话有关的监听器接口

HttpSessionListener处理会话事件(会话创建、销毁)

HttpSessionAttributeListener属性添加、替换、移除事件

HttpSeesionActivationListener(分布式应用,需要跨越其他服务器时,回话转移事件)

HttpSessionBindingListener

3、与请求有关的监听器接口

ServletRequestListener接口针对请求事件创建监听器类

⏹定义的方法

ØrequestInitialized()

ØrequestDestroy()

ServletRequestAttributeListener接口用于对Servlet的Request属性变化事件进行监听。

6)会话

◆会话概念

◆会话管理是指如何在会话范围内共享信息

◆不是所有的Web应用都需要会话管理

◆通过Cookie可以跟踪会话

◆通过URL重写可以跟踪会话

◆通过HttpSession可以跟踪会话

HttpSession的使用

◆HttpSession接口可以方便Servlet容器进行会话跟踪,实际上是建立在Cookie和URL重写这两种会话跟踪技术之上的

◆调用HttpSession接口的setMaxInactiveInterval方法设置会话的超时时间,时间毫秒

◆调用HttpSession接口的invalidate方法可以终止会话

◆可以在web.xml中设置会话的超时时间,时间的单位是分钟

方法名称

回传类型

说明

getAttribute(Stringname)

Object

从HTTP会话内取得某个属性

getAttributeNames()

Enumeration

从HTTP会话内取出所有属性名称

invalidate()

void

终止某个HTTP会话

setAttribute(Stringname,Objectvalue)

void

将某个对象绑定至HTTP会话,成为其属性之一

removeAttribute(Stringname)

void

从HTTP会话内移除某个属性

setMaxInactiveInterval(intinterval)

void

设定某个HTTP会话的“超时”(timeout)时间

7)ServletContext对象

向Web应用范围内添加属性和获取属性的方法

三、JSP

1、生命周期

解析阶段:

解析JSP代码语法

翻译阶段:

翻译成Servlet源文件

编译阶段:

编译成Servlet类

初始化阶段:

加载类,创建其实例,调用初始化方法

运行阶段:

调用服务方法

销毁阶段:

调用销毁方法

或者:

JSP的生命周期分为:

转换、编译、创建对象、处理请求、销毁五个阶段

生命周期方法调用顺序是:

jspInit(),_jspService(),jspDestroy()

2、表达式

JSP标签种类

语法

用途

StandardDirective

<%@JSP标准指令(与其属性)%>

设定JSP网页的整体配置信息,分为page、include与taglib三种

DeclaractionTag

<%!

声明式%>

声明JSP内所使用的变量或方法

ScriptletTag

<%Java程序代码%>

撰写任何Java程序代码

ExpressionTag

<%=表达式%>

撰写任何Java表达式

CommentsTag

<%--注解文字处理--%>

撰写JSP的注解文字

StandardAction

动作项目属性=“属性值”/>

运行特定动作,可以减少某些Java程序代码

JSP标签与使用范例

JSP文件相对应的XML元素

DirectiveTag

<%@pageimport=“java.util.*”%>

directive.page

import=“java.util.*”/>

DeclaractionTag

<%!

inti=1;%>

declaraction>

inti=1;

declaraction>

ScriptletTag

<%if(x>0){result=true;}%>

scriptlet>

if(x>0){result=true}

scriptlet>

ExpressionTag

<%=newDate()%>

expression>

newDate()

espression>

CommentsTag

<%--i变量用来计算循环次数--%>

无(使用HTML注解方式)

●例:

<%=1+3%>

<%=newDate()%>

experisson>1+3

expression>

experisson>newDate()

expression>

<%@ageimport=”java.util.ArryList”%>

directive.pageimport=“java.util.*”/>

<% !

inti=0 ;%>

declaraction>inti=1;

declaraction>

●考虑:

<% !

inti=0 ;%>和

<%=1+3%>

这两行代码,被编译成Servlet时会放在哪个方法里?

●考虑如何在JSP页面实现包含,两种包含的特点

<%@includefile=“目标组件的绝对URL或相对URL”%>静态

includepage=“URL”/>动态

●请求转发的实现,如何传请求参数

forwardpage=url>

param>

forward>

3、内置对象(对象名,范围,作用)

P121表4-3

4、EL表达式

●语法:

${表达式}

P122表4-4、4-5

●关于.和[]操作符的使用

⏹${name.property}等价于${name["property"]}

⏹访问数组中的元素,使用“[]”,${customers[0]}

⏹${header[“user-ent”]}就不能使用${header.user-agent}

 

●隐式对象:

P123表4-6

●empty运算符的使用

以下情况empty运算符返回true${var}

Øvar变量不存在,即没有被定义。

Øvar变量的值为null。

Øvar变量引用集合(Set、List、Map)类型的对象,并且在集合对象中不包含任何元素

Øempty运算符可以与”!

”运算符一起使用。

${23+15.28}

${12>10}

5、范围(page.equest、session、application)

如何显示某范围内的数据?

${requestScope.param1}或者${param1}

下面代码什么结果?

<%

request.setAttribute("t1","5");

request.setAttribute("t2",newInteger

(2));

%>

test1=${t1+t2}

test2=${10-t2}

test3=${10-t1+t2}

test4=${t1}+${t2}

四、EJB

1、EJB概念

2、EJB3.0包含的bean种类(无状态会话bean、有状态会话bean、消息驱动bean)

无状态会话Bean保存会话状态

无状态会话Bean使用@Stateless标注定义

无状态会话Bean实例能在多个客户端共享

无状态会话Bean使用实例池

有状态会话Bean能够保存会话的状态

有状态会话Bean使用@Stateful标注定义

有状态会话Bean实例不能在多个客户端共享

有状态会话Bean不使用实例池

3、JPA包括在J2EE5规范中,

JPA借助持久化提供者操作实体

实体的生命周期包括新建、受管、分离、删除四个阶段

实体对应数据库中的表

4、

三、程序运行

 

四、程序代码部分:

一、在一个采用了分层体系结构的Web应用的持久化层中使用了DAO设计模式,DAO类BookDaoJDBCImpl中封装了对数据库中存放书籍信息的Books表进行增、删、改、查询操作的方法,

publicclassBook{

privateStringname;

privateStringauthor;

privateStringpublisher;

privateStringisbn;

privatedoubleprice;

publicBook(Stringname,Stringauthor,Stringpublisher,Stringisbn,doubleprice){

this.name=name;

this.author=author;

this.publisher=publisher;

this.isbn=isbn;

this.price=price;

}

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicStringgetAuthor(){

returnauthor;

}

publicvoidsetAuthor(Stringauthor){

this.author=author;

}

publicStringgetPublisher(){

returnpublisher;

}

publicvoidsetPublisher(Stringpublisher){

this.publisher=publisher;

}

publicStringgetIsbn(){

returnisbn;

}

publicvoidsetIsbn(Stringisbn){

this.isbn=isbn;

}

publicdoublegetPrice(){

returnprice;

}

publicvoidsetPrice(doubleprice){

this.price=price;

}}

DAO类:

publicclassBookDaoJDBCImplimplementsBookDao{

privateDataSourceds;

publicBookDaoJDBC()throwsException{

Contextctx=newInitialContext();

ds=(DataSource)ctx.lookup("jdbc/myDatasource");

}

publicListfindAll()throwsException{

Listlist=newArrayList();

Connectioncon=ds.getConnection();

Statementst=con.createStatement();

ResultSetrs=st.executeQuery("select*fromapp.book");

while(rs.next()){

Bookbook=newBook(rs.getString

(1),rs.getString

(2),rs.getString(3),rs.getString(4),rs.getDouble(5));

list.add(book);

}

rs.close();

st.close();

con.close();

returnlist;

}

publicvoidremove(Stringid)throwsException{

Connectioncon=ds.getConnection();

PreparedStatementpst=con.prepareStatement("deletefromapp.bookwhere书号=?

");

pst.setString(1,id);

pst.executeUpdate();

pst.close();

con.close();

}

publicvoidupdate(Bookbook)throwsException{

Connectioncon=ds.getConnection();

PreparedStatementpst=con.prepareStatement("updateapp.bookset姓名=?

作者=?

出版社=?

价格=?

where书号=?

");

pst.setString(1,book.getName());

pst.setString(2,book.getAuthor());

pst.setString(3,book.getPublisher());

pst.setDouble(4,book.getPrice());

pst.setString(5,book.getIsbn());

pst.executeUpdate();

pst.close();

con.close();

}

publicvoidadd(Bookbook)throwsException{

Connectioncon=ds.getConnection();

PreparedStatementpst=con.prepareStatement("insertintoapp.bookvalues(?

?

?

?

?

)");

pst.setString(1,book.getName());

pst.setString(2,book.getAuthor());

pst.setString(3,book.getPublisher());

pst.setString(4,book.getIsbn());

pst.setDouble(5,book.getPrice());

pst.executeUpdate();

pst.close();

con.close();

}

publicBookfindById(Stringid)throwsException{

Connectioncon=ds.getConnection();

Statementst=con.createStatement();

ResultSetrs=st.executeQuery("select*fromapp.bookwhere书号='"+id+"'");

Bookbook=null;

while(rs.next()){

book=newBook(rs.getString

(1),rs.getString

(2),rs.getString(3),rs.getString(4),rs.getDouble(5));

}

returnbook;

}

}

二、参考上面内容:

在一个采用了分层体系结构的Web应用的持久化层中使用了DAO设计模式,DAO类CustomerDaoJDBCImpl中封装了对数据库中存放客户信息的customer表进行增、删、改、查询操作的方法,

Customer表字段:

number、name、phone、email

对应的Customer类

publicclassCustomer{

privateStringnumber;//编号

privateStringname;//名字

privateStringphone;//电话

privateStringemail;//电子邮箱

//省略

}

DAO类

publicclassCustomerDaoJDBCImplimplementsStudentDao{

privateDataSourceds;

publicStudentDaoJDBCImpl()throwsException{

Contextctx=newInitialContext();

ds=(DataSource)ctx.lookup("jdbc/sample");

}

/*添加客户信息的方法*/

publicvoidadd(Customerc)throwsException{

..}

/*查找所有客户信息的方法*/

publicListfindAll()throwsException{

}

/*更新客户信息的方法*/

publicvoidupdateCustomer(Customerc){

/**/

}

/*删除客户信息的方法*/

publicvoiddeleteCustomer(Customerc){

/**/

}

}

四、在一个采用了分层体系结构的Web应用StudentApp的持久化层中使用了DAO设计模式,DAO类StudentDaoJDBCImpl中封装了对数据库中存放学生信息的students表进行增、删、改、查询操作的方法。

Student表:

number、name、phone、email

p

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

当前位置:首页 > 高中教育 > 其它课程

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1