首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

ssh框架的要端记录

2012-11-06 
ssh框架的要点记录1.action中将属性传递到jsp页面:(此处有两种方法)方法一:ActionContext actActionConte

ssh框架的要点记录

1.action中将属性传递到jsp页面:(此处有两种方法)

方法一:

ActionContext act=ActionContext.getContext();
act.put("users", users);

jsp页面中获取: ${users.name}

?

采用OGNL表达式获取<br/>?
<s:iterator value="#request.employees">?
??? <s:property value="username"/>,<s:property value="password"/>,<s:property value="gender"/><br/>?
</s:iterator>?
<br/>采用JSTL/EL表达式获取<br/>?
<c:forEach var="emp" items="${employees}" varStatus="st">?
??? ${emp.username},${emp.password},${gender}<br/>?
</c:forEach>?

?

方法二:

在action中定义private String mes ;再给该变量生成get和set 方法

mes="对不起,您的用户名或密码有误啊!";

jsp页面中获取: ${mes}

?

2.清除session:

清除某一个session:session.removeAttribute("session中变量名");

如果要清除所有session:session.invalidate();

?

3.在jsp页面中获取当前项目名称:
<%=this.getServletContext().getContextPath() %>
通过标签: ${pageContext.request.contextPath}

?

4.spring可以启用注解的方式来配置属性:
重新这样配置bean
<bean id="employeeService" class="com.cz.service.imp.EmployeeService"/>
在EmployeeService 的属性sessionFactory中添加一个注解 @Resource
在applicationContext.xml中启用注解
<context:annotation-config/>

?

5.懒加载解决:
${loginuser.department.name} 时候,懒加载问题出现。
解决思路:
明确初始化
方法一:在session还没有关闭时,访问一次 xxx.getXxx(),强制访问数据库。或者Hibernate.initialize(Deparment.class);//select预先查询

方法二:在对象映射文件中 取消懒加载? <lazy=”false”/>

上面方法问题是: 不管你在jsp中使不使用部门的名称,它都有向数据库发出select 请求.
方法三:Spring专门提供了opensessioninview的方法来解决懒加载.
需要在web.xml文件中添加如下配置:
<filter>
??????? <filter-name>OpenSessionInViewFilter</filter-name>
??????? <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
??????? <filter-name>OpenSessionInViewFilter</filter-name>
??????? <url-pattern>/*</url-pattern>
</filter-mapping>
该方法可以有效的减少对数据库的查询,缺点是和数据保持的session,时间延长了.

热点排行