请教open session in view

05-08-30 sha1979
刚刚接触Spring,我想做个练习,但总出错;

struts1.1 + hibernate3+spring1.2.1+Tomcat5

我想使用open session in view模式

hibernate中以设置成lazy="true"。

抱错:session 以关闭

配置如下

web.xml

?xml version="1.0" encoding="UTF-8"?

!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"

web-app

display-name wish /display-name

context-param

param-name contextConfigLocation /param-name

param-value /WEB-INF/applicationContext.xml /param-value

/context-param

filter

filter-name hibernateFilter /filter-name

filter-class org.springframework.orm.hibernate3.support.OpenSessionInViewFilter /filter-class

init-param

param-name singleSession /param-name

param-value false /param-value

/init-param

/filter

filter-mapping

filter-name hibernateFilter /filter-name

url-pattern *.do /url-pattern

/filter-mapping

listener

listener-class org.springframework.web.context.ContextLoaderListener /listener-class

/listener

servlet

servlet-name action /servlet-name

servlet-class org.apache.struts.action.ActionServlet /servlet-class

init-param

param-name config /param-name

param-value /WEB-INF/struts-config.xml /param-value

/init-param

init-param

param-name debug /param-name

param-value 2 /param-value

/init-param

init-param

param-name application /param-name

param-value ApplicationResources /param-value

/init-param

load-on-startup 2 /load-on-startup

/servlet

servlet-mapping

servlet-name action /servlet-name

url-pattern *.do /url-pattern

/servlet-mapping

.........................

...........................

/web-app

struts-config.xml如下

?xml version="1.0" encoding="UTF-8"?

!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"

"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"

struts-config

form-beans

form-bean name="lazyForm" type="sixhero.actionForm.LazyForm" /

/form-beans

action-mappings

action name="lazyForm" path="/test/lazyAction" scope="request"

type="org.springframework.web.struts.DelegatingActionProxy"

forward name="ok" path="/test/ok.jsp" /

forward name="no" path="/test/no.jsp" /

/action

/action-mappings

message-resources parameter="ApplicationResources" /

plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"

set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" /

/plug-in

/struts-config

ok.jsp如下

%@ page contentType="text/html; charset=GB2312" %

%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %

%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %

%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %

%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %

%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %

%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %

html

head

title

ok

/title

/head

body bgcolor="#ffffff"

logic:notEmpty name="list"

logic:iterate id="temp" name="list"

bean:write name="temp" property="UserName"/

br

bean:write name="temp" property="forumDescript"/

br

br

bean:write name="temp" property="Order.name" filter="true"/

br

br

/logic:iterate

/logic:notEmpty

/body

/html

Order.name总是抱错

              

1
banq
2005-08-30 17:29
是小写的order.name

sha1979
2005-09-01 10:33
谢谢您的回答:我试了.我哪个关连字段是Order

struts能不能用open session in view,是不是只有用spring mvc才能用.struts中应该怎么用?或哪里有相关的例子.

banq
2005-09-01 10:49
open session in view是你必须做一种过滤器,一直保持Hibernate的session打开,这和Spring有什么关系?Spring是个可有可无的东西,只不过它开发很多方便的API。

在struts中,Jsp中的order的意思不是你的关联字段,而是相应的getOrder方法,将get去除,O变成小写,所以无论你的字段是大小写,反正Jsp中order是小写,试试一下就知道了。

sha1979
2005-09-01 10:52
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

这个类是否就是Filter,直接用可不可以。

猜你喜欢
4Go 1 2 3 4 下一页