以下是JS代码----------------------------------
function js_loadCateogry(id)
{
dwr_updateCategory.loadCategory(id,loaded);
}
function loaded(isExits)
{
if(isExits!=null){
document.getElementById("upatename").value='${updateCategory.cname}';
document.getElementById("upatetype").value='${updateCategory.ctype}';
document.getElementById("upateintro").value='${updateCategory.cintro}';
}
}
--------------------------------------------------------------------------------
以下是方法,该方法是对的,我在Action中调用的话,能够得出我想要的值
public Category loadCategory(int cid) {
try {
return (Category)basicDAO.load(Category.class, cid);
} catch (Exception e) {
e.printStackTrace();
throw new AppException("载入收支类目失败!");
}
}在js中调用,id在loadCategory(int cid)中已经传递过去,但却return为null,出现空指针异常
请问怎么解决?对Ajax不是很懂
另外,怎么在js中得到返回的对象?
function js_loadCateogry(id)
{
dwr_updateCategory.loadCategory(id,loaded);
}
function loaded(isExits)
{
if(isExits!=null){
document.getElementById("upatename").value='${updateCategory.cname}';
document.getElementById("upatetype").value='${updateCategory.ctype}';
document.getElementById("upateintro").value='${updateCategory.cintro}';
}
}
--------------------------------------------------------------------------------
以下是方法,该方法是对的,我在Action中调用的话,能够得出我想要的值
public Category loadCategory(int cid) {
try {
return (Category)basicDAO.load(Category.class, cid);
} catch (Exception e) {
e.printStackTrace();
throw new AppException("载入收支类目失败!");
}
}在js中调用,id在loadCategory(int cid)中已经传递过去,但却return为null,出现空指针异常
请问怎么解决?对Ajax不是很懂
另外,怎么在js中得到返回的对象?
解决方案 »
- 急,大家帮帮忙,IO异常,在线等
- ant的build文件报错。。
- Could not parse configuration: /com/ccit/entca/conf/hibernate.cfg.xml 在线急等!!!
- 小弟求救
- dom4j解析xml问题 帮忙做一下 谢谢
- xfire 如何调用.net web services
- hibernate配置问题,很急。路过的请进来。。。。。。。。。。
- 一次取出3万多条记录,这个时候使用rs.next()遍历,共耗时37秒,正常么?
- struts中bean:write的farmat属性怎么用
- J2EE的EJB规范应用问题
- Hibernate update(obj)异常 Unexpected row count: 137 expected: 1
- EJB3中的一个串行异常
很奇怪load(Category.class, cid)这两个参数都有值,但返回的却是空
数据库里有这条记录的
感觉是load方法用的不对
首先cid是实例Category的主键吗。如果是的话,没道理查不出来。如果不是的话你这么写肯定查不出结果
网上的一解决方法,
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/dwr/*</url-pattern>
</filter-mapping>
不过没效果~~
-------------------------------------------------------------
这是我dwr.xml中的配置
<dwr>
<allow>
<create javascript="dwr_updateCategory" creator="spring">
<param name="beanName" value="categoryManager" />
<param name="location" value="classpath:applicationContext-*.xml" />
<include method="loadCategory"/>
</create>
<convert match="com.financeMaster.domain.Category" converter="bean"></convert>
</allow>
</dwr>
//根据ID载入该对象
public Object load(Class clazz,java.io.Serializable id);
------------BasicDAOImpl------------
//根据ID载入该对象
public Object load(Class clazz, Serializable id) {
return getHibernateTemplate().load(clazz, id);
}
-----------CategoryManager------------
//载入某一收支类目
public Category loadCategory(int cid);
----------CategoryManagerImpl------------
//载入某一收支类目
public Category loadCategory(int cid) {
try {
return (Category)basicDAO.load(Category.class, cid);
} catch (Exception e) {
e.printStackTrace();
throw new AppException("载入收支类目失败!");
}
}
把hibernate配置的show_sql打开
sql直接运行下就知道了
在5楼你看下,后代码贴在7楼
或者在web.xml中配置spring的OpenSessionInViewFilter过滤器,也能解决。