添加dwr jar包
dwr.xml
web.xml
applicationContext.xml:
*.jsp:
dwr.xml
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr//dwr20.dtd">
<dwr>
<allow>
<create creator="spring" javascript="ajaxcommon">
<param name="beanName" value="ajaxCommasd" />
</create>
<!-- convert converter="bean" match="org.lottery.LMMS.data.SysUser">
<param name="include" value="id,sysUserid,name,password"/>
</convert-->
</allow>
</dwr>
web.xml
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
applicationContext.xml:
<bean id="ajaxCommasd" class="com.singleusers.ajax.AjaxCommon">
<property name="userService" ref="userService"></property>
</bean>
<bean id="userDao" class="com.singleusers.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean>
<bean id="userService" class="com.singleusers.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
*.jsp:
<script type='text/javascript' src='/SingleUsers/ajax/interface/ajaxcommon.js'></script>
<script type='text/javascript' src='/SingleUsers/ajax/engine.js'></script>
<script type='text/javascript' src='/SingleUsers/ajax/util.js'></script>
<script type="text/javascript">
function reloadym(id)
{
alert(id);
document.location.reload(true);
}
function ajaxdel(id)
{
alert("ajax");
alert(id);
ajaxcommon.doChange(id,reloadym);
}
</script>
<button οnclick="ajaxdel(27);">提交</button>
AjaxCommon AjaxCommon.java:
package com.singleusers.ajax;
import com.singleusers.service.UserService;
import com.singleusers.user.bean.userid;
public class AjaxCommon {
private UserService userService;
public int doChange(int id){
System.out.println(id);
userid user =new userid();
user.setId(id);
userService.delete(user);
return id;
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
}