<html>
<body>
<table border="1" bgcolor="#000000" align="center" width="50%">
<tr >
<th bgcolor="#ffffff" align="right">时间:</th>
<th bgcolor="#ffffff"><div id="nowDiv"></div> </th>
</tr>
<tr>
<th bgcolor="#ffffff"><h3 align="left">今日更新</h3></th>
</tr>
<s:iterator value="#session.newNotice" status="list" >
<s:hidden name="id" value="<s:property value='id' />" />
<tr> <td bgcolor="#ffffff" ><s:property value="#list.getIndex()+1"/></td></tr>
<tr><td bgcolor="#ffffff" ><s:property value="title" /></td></tr>
<tr><td bgcolor="#ffffff"><s:property value="type" /></td></tr>
<tr><td bgcolor="#ffffff" ><s:property value="content" /></td></tr>
<tr><td bgcolor="#ffffff" ><s:property value="published" /></td></tr>
</s:iterator>
</table>
</body>
</html>可是页面显示时调用struts那块内容却无法显示
我的控制端代码是这样的:public String selectNotice()throws Exception{
List<DormNotice> list=new ArrayList();
dormNoticeDAO=new DormNoticeDAO();
list=dormNoticeDAO.searchNotice();
if(list==null){
System.out.println("查询结果不存在");
}
else{
ActionContext ctx = ActionContext.getContext();
Map map = ctx.getSession();
map.put("newNotice", list);
}
return SUCCESS;
}麻烦大家帮帮忙.....
下面我想显示的关于数据内容并没有
我希望的是table里显示公告的
题目 title
类型 type
内容 content
发布时间 published
把你的status="list" 改成 id="list" <tr><td bgcolor="#ffffff" ><s:property value="title" /></td></tr>
<tr><td bgcolor="#ffffff"><s:property value="type" /></td></tr>
<tr><td bgcolor="#ffffff" ><s:property value="content" /></td></tr>
<tr><td bgcolor="#ffffff" ><s:property value="published" /></td></tr>
把value="title"改成 value="#list.title" 往下同理
我改过之后 就谈出错误了:
Servlet.service() for servlet default threw exception
java.lang.NullPointerException
at com.txsm.crm.dao.BaseDAO.getSession(BaseDAO.java:20)
at com.txsm.crm.dao.impl.DormNoticeDAO.searchNotice(DormNoticeDAO.java:43)
at com.txsm.crm.service.impl.DormService.selectNotice(DormService.java:36)
at com.txsm.crm.action.DormNoticeAction.selectNotice(DormNoticeAction.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction
BaseDAO文件是这样的: package com.txsm.crm.dao;import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;public class BaseDAO {
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory()
{
return sessionFactory;
} public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Session getSession()
{
Session session=sessionFactory.openSession();
return session;
}
}
然后我发现applicitinContext配置文件里只有
<property name="mappingResources">
<list> <value>com/txsm/crm/vo/Userinfo.hbm.xml</value></list>
</property>
的配置,但是com/txsm/crm/vo包了还有一个DormNotice.hbm.xml的文件
现在我该怎么做啊....
<value>com/txsm/crm/vo/DormNotice.hbm.xml</value>
<s:property value="#stuts.index+1"/>
是你这里有问题吧,
public Session getSession()
{
Session session=sessionFactory.openSession();
return session;
}应该不是sessionFactory.openSession()吧,而是sessionFactory.getCurrentSession();
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: entity class not found: com.txsm.crm.vo.DormNotice
Caused by: org.hibernate.MappingException: entity class not found: com.txsm.crm.vo.DormNotice
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:166)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:115)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:216)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 数据库连接信息 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.jdbc.sqlserver.SQLServerDriver">
</property>
<property name="url" value="jdbc:microsoft:sqlserver://localhost:1433;Database=test">
</property>
<property name="username" value="sa"></property>
<property name="password" value="sa"></property>
</bean>
<!-- sessionFactory 注入 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/txsm/crm/vo/Userinfo.hbm.xml</value>
<value>com/txsm/crm/vo/DormNotice.hbm.xml</value>
</list>
</property>
</bean>
<!-- BaseDAO 注册 -->
<bean id="baseDAO" class="com.txsm.crm.dao.BaseDAO" abstract="true">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- UserinfoDAO 注册 -->
<bean id="userinfoDAO" class="com.txsm.crm.dao.impl.UserinfoDAO" parent="baseDAO"/>
<!-- DormNoticeDAO 注册 -->
<bean id="DormNoticeDAO" class="com.txsm.crm.dao.impl.DormNoticeDAO" parent="baseDAO"/>
<!-- UserService 注册 -->
<bean id="userService" class="com.txsm.crm.service.impl.UserService">
<property name="userDAO">
<ref bean="userinfoDAO"/>
</property>
</bean>
<!-- DormService 注册 -->
<bean id="dormService" class="com.txsm.crm.service.impl.DormService">
<property name="dormNoticeDAO">
<ref bean="DormNoticeDAO"/>
</property>
</bean>
<!-- UserAction 注册 -->
<bean id="userAction" class="com.txsm.crm.action.UserAction">
<property name="userService">
<ref bean="userService" />
</property>
</bean>
<!--DormNoticeAction注册 -->
<bean id="dormNoticeAction" class="com.txsm.crm.action.DormNoticeAction">
<property name="dormService">
<ref bean="dormService" />
</property>
</bean>
</beans>
at com.txsm.crm.dao.BaseDAO.getSession(BaseDAO.java:20)
at com.txsm.crm.dao.impl.DormNoticeDAO.searchNotice(DormNoticeDAO.java:43)
at com.txsm.crm.service.impl.DormService.selectNotice(DormService.java:36)
at com.txsm.crm.action.DormNoticeAction.selectNotice(DormNoticeAction.java:39楼主 是你的session没有获取到,多检查下配置。
ActionContext act=ActionContext.getContext();
Map map=act.getSession();
map.put("newNotice", list);
这段代码写错位置了 我原来是将它写在service里的 当然这应该是个低级错误 将它写在action就可以了
贴出来大家分享下....