《深入浅出struts》读书笔记(2)

第七章JSTL

通用动作

Out标签

<c:out value=””/>

例:<c:out values=”${sessionScop.myVar}”>

Set标签:创建作用域对象,创建后同一个JSP页面可以使用

<c:set var=”foo” value=”the wisest fool” scope=””>

Remove标签 移除作用域变量

条件动作

<c:if test=”${param.user==’ken’&&param.password=’blackcomb’}”>

You logged in successfully

</c:if>

Choose when otherwise标签

<c:choose>

<c:when test=”${param.status==’full’}”>

You are a full member

</when>

<c:when test=”${param.status==’student’}”>

</when>

</c:choose>

遍历

<c:forEach var=”phone” items=”${address.phones}”>

<c:out value=”${phone}”>

</c:foreach>

…………..

12

Tiles框架 一种页面布局方式

第十五章 持久层

本章主要介绍DAO模式,在DAO模式中,程序员需要为持久存储的每一种数据类型编写一个相应的类。如果要存储三个传输对象,就需要编写三个DAO类,每个类处理一种数据类型,productDAOCustomDAO等。类名后面的DAO后缀表示该类是一个DAO类。

1:使用DAO接口的DAO模式

最顶层接口DAO 方法getConnection()

DAOBase实现DAO接口,在DAOBase类中,使用Config类来进行数据库的配置。

Public class Config{

Private static Config configInstance;

Private Map map=new HashMap();

Static{

       Try{

ConfigInstance=new Config();

}

Catch(){}

}

Public static Config getInstance()

{

Return configInstance;

}

Public void addKeyValue(String key,Object value)

{

Map.put(key,value);

}

Public Object getValue(String key)

{

Return map.get(key);

}

Public Map getMap()

{

Return map;

}

}

需要一个监听器来读取配置

Public class AppListener implements ServletContextListener{

         Public void contextInitialized(ServletContextEvent cse){

         Try{

         Config config=Config.getInstance();

         ServletContext sc=cse.getServletContext();

         Enumeration parameters=servletContext.getInitParameterNamses();

         While(parameters.hasMoreElements())

         {

                   String parameter=(String)parameters.nextElements();

                   Config.addKeyValue(parameter,servletContext.getInitParameter(parameter));

}

}

}

Action中使用

{

         Config config=Config.getInstance();

         Map map=config.getMap();

         Request.setAttribute(“map”,map);

}

………….

有了DAOBase类之后,各个DAO类继承DAOBase类。例如ProductDAO类,该类有getProduct searchProduct createProduct updateProduct deleteProduct等方法。

2:使用抽象工厂的模式来实现DAO模式

除了上述的类和接口外,在增加一成CustomDAO接口,实现的时候为CustomDAOMySQLImp表示CustomDAOMySqL数据库上的实现。

注意链接的时候使用DataSource

17 文件上传和下载

上传FormFile类。。。。。

posted @ 2009-07-26 22:30  macula7  阅读(171)  评论(0编辑  收藏  举报