一:request对象
原来学的对request对象的写入是靠aware接口
//实现RequestAware,SessionAware,ApplicationAware三个接口,用于读写web对象
public class WebObjectAction01 extends ActionSupport implements RequestAware,SessionAware,ApplicationAware
{
private Map<String,Object> request;//这仨名字固定,因为下边接口的set函数名固定。不然反射时候找不到
private Map<String,Object> session;
request.put("req1", "valueOfReq1");
显示时:
<s:property value="#request.req1" /> -IS- <%=request.getAttribute("req1") %> <br/>
<s:property value="#session.ses1" /> -IS- <%=session.getAttribute("ses1") %> <br/>
<s:property value="#application.app1" /> -IS- <%=application.getAttribute("app1") %> <br/>
大概是这样
这回见到一个新的方式:
public class BlogMainAction extends ActionSupport implements
ServletRequestAware {
protected HttpServletRequest request;
request.setAttribute("userVistor", userVistor);
显示时:
<s:iterator value="%{#request.articleVistor}" id="articleVistor">
<s:iterator value="%{#request.articleCommend}" id="articleCommend">
这样强行转换成字串
二:action的构造里完成筛选
博客首页上有一堆推荐
比如访问量最高的文章等,主页action的一大职责就是筛选这些信息
hql_article_vistor = "from ArticleInfo where author in (select account from UserInfo where freeze='解冻') order by visit desc";
}
// 以下是热门文章
List<ArticleInfo> articleVistor = articleDao
.queryListObject(hql_article_vistor);
if (articleVistor.size() > 5) {
articleVistor = articleVistor.subList(0, 5);
}
之前Hibernate的Dao里就准备好了对查询结果的截取,这用的是取前5名
三:首页上推荐信息的显示:
显示的主要内容是从上边的articleVistor中取得的。
一是取得id,用来给后边的action传值
二是取得标题,用于首页显示
<s:iterator value="%{#request.articleVistor}" id="articleVistor">
<tr align="center">
<td height="30" background="<%=request.getContextPath()%>/images/f_certer.gif"><a href="articleInfo_f_article_query.htm?id=<s:property value="#articleVistor.id"/>" target="_blank"><s:property value="#articleVistor.title"/></td>
</tr>
</s:iterator>
<tr>
其余推荐信息大同小异,实现方式类似