DWR初学测试

rightrian 2010-10-19 10:55:24

<!-- DWR -->
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
这个web.xml中的配置。。

Java code<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
" http://directwebremoting.org/schema/dwr20.dtd">


<dwr>
<allow>
<convert match="com.house.system.ssh.project.entity.User"
converter="bean">
</convert>
<create creator="new" javascript="UserBizImpl">
<param name="class"
value="com.house.system.ssh.project.Biz.impl.UserBizImpl" />
</create>

</allow>
</dwr>

dwr.xml配置

Java code
@SuppressWarnings("unchecked")
public boolean existUser(String uname) {
boolean exist=false;
try {
String hql = "from User where uname='" + uname + "'";
Query query = this.getSession().createQuery(hql);
List list=query.list();
if(list!=null && list.size()>=0){
exist=true;
return exist;
}
} catch (RuntimeException e) {
throw e;
}
return exist;
}


UserDaoImpl实现方法

Java code
public boolean existUser(String uname) {
return userDao.existUser(uname);
}

UserBizImpl里调用

为什么老是弹出error错误,在测试String型方法的时候 在dao和Imp层调用可以 ,在Biz和BizImpl就不行了 error错误
换成boolean型的时候 在那个层用都不行测试方法都对的 就是error错误 是不是配置问题啊 急啊









...全文
113 点赞 收藏 11
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
rightrian 2010-10-19
[Quote=引用 2 楼 zhuchao_ko 的回复:]
jsp页面的代码呢?

JSP页面记得把3个JS引入进来。
[/Quote]
引用了
回复
宁波朱超 2010-10-19
jsp页面的代码呢?

JSP页面记得把3个JS引入进来。
回复
hpj2000 2010-10-19
描述一下error错误,看看报什么错。
回复
rightrian 2010-10-19
[Quote=引用 9 楼 rightrian 的回复:]
引用 8 楼 sustbeckham 的回复:
我猜的啊

看了异常 你用到了spring
看了代码 你用了Hibernate

<dwr>
<allow>
<convert match="com.house.system.ssh.project.entity.User"
converter="bean">
</convert>
<create creator="new" j……
[/Quote]

应为我在学习 ,,都的用上
回复
sustbeckham 2010-10-19
[Quote=引用 9 楼 rightrian 的回复:]

引用 8 楼 sustbeckham 的回复:
我猜的啊

看了异常 你用到了spring
看了代码 你用了Hibernate

<dwr>
<allow>
<convert match="com.house.system.ssh.project.entity.User"
converter="bean">
</convert>
<create creator="new" ……
[/Quote]

那干嘛要用spring?....
回复
rightrian 2010-10-19
[Quote=引用 8 楼 sustbeckham 的回复:]
我猜的啊

看了异常 你用到了spring
看了代码 你用了Hibernate

<dwr>
<allow>
<convert match="com.house.system.ssh.project.entity.User"
converter="bean">
</convert>
<create creator="new" javascript="User……
[/Quote]

貌似有点意思。。我是什么也没交给spring管理
回复
sustbeckham 2010-10-19
我猜的啊

看了异常 你用到了spring
看了代码 你用了Hibernate

<dwr>
<allow>
<convert match="com.house.system.ssh.project.entity.User"
converter="bean">
</convert>
<create creator="new" javascript="UserBizImpl">
<param name="class"
value="com.house.system.ssh.project.Biz.impl.UserBizImpl" />
</create>

</allow>
</dwr>
但是这样是dwr的基本用法 也就是在什么框架都没有的情况下的使用

在有spring的框架下 应该dwr和spring集成起来
是应该类似于这样的
<create javascript="myplan" creator="spring">
<param name="beanName" value="planServiceBean spring的bean id"></param>
<include method="getPrivateList"/>
</create>
<convert match="com.sust.bean.user.Admin" converter="bean"></convert>

个人意见 仅供参考。
回复
rightrian 2010-10-19
[Quote=引用 6 楼 adamliuhui 的回复:]
LS的是配置的Spring事务 不正确。改下 你应该懂得的吧?
[/Quote]
我没有配置事务啊
回复
_LiuHui 2010-10-19
LS的是配置的Spring事务 不正确。改下 你应该懂得的吧?
回复
rightrian 2010-10-19


org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
回复
rightrian 2010-10-19

<script type='text/javascript' src='/HouseSystem/dwr/interface/UserBizImpl.js'></script>
<script type='text/javascript' src='/HouseSystem/dwr/engine.js'></script>
<script type='text/javascript' src='/HouseSystem/dwr/util.js'></script>


<script type="text/javascript">
function validate()
{
var username = document.getElementById("username").value;
UserDaoImpl.existUser(username,show) ;

}
function show(boolean)
{

if(boolean)
{
$("error").style.visibility = "visible" ;
document.getElementById("username").value="";

}
else
{
$("error").style.visibility = "hidden" ;

}
}





HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
com.house.system.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:45)


root cause

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1182)
org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:692)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
com.house.system.ssh.project.dao.impl.UserDaoImpl.Register(UserDaoImpl.java:99)
com.house.system.ssh.project.biz.impl.UserBizImpl.Register(UserBizImpl.java:36)
com.house.system.ssh.project.action.UserAction.Register(UserAction.java:90)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
com.house.system.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:45)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.




回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2010-10-19 10:55
社区公告
暂无公告