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,时间延长了.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值