Dwr级联的小例子
1.引入DWR包
2.配置web.xml文件
[html]
<!-- DWR配置 -->
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>crossDomainSessionSecurity</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<!-- DWR配置结束 -->
3.WEB-INFO下新建dwr.
xml
[html]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
<allow>
<!-- 测试DWR配置开始 -->
<convert converter="bean" match="com.estone.www.bjkpcg.manage.ztest.Per"></convert>
<create creator="new" javascript="service">
<param name="class" value="com.estone.www.bjkpcg.manage.ztest.HelloWorld"/>
</create>
<!-- 测试DWR配置结束 -->
<!--批次实体配置-->
<convert converter="bean" match="com.estone.www.bjkpcg.manage.project.vo.TblCgBatch"></convert>
<convert converter="bean" match="com.estone.www.bjkpcg.manage.production.vo.TblCgProductionType"></convert>
<!--项目类别配置-->
<create creator="new" javascript="dwrMethod">
<param name="class" value="com.estone.www.bjkpcg.util.DwrMethod"/>
</create>
<!--项目类型实体配置-->
<convert converter="bean" match="com.estone.www.bjkpcg.manage.project.vo.TblCgProjectType"></convert>
<!--项目信息添加配置-->
<create creator="new" javascript="projectDwr">
<param name="class" value="com.estone.www.bjkpcg.network.project.dwr.ProjectDwr"/>
</create>
</allow>
</dwr>
4.Dwr类
[java]
public class Dwr{
//获取上下文关系
private WebContext getWebContext() {
return WebContextFactory.get();
}
//获取sesion
public HttpSession getSession() {
return getWebContext().getSession();
}
//获取Request
public HttpServletRequest getHttpServletRequest() {
return getWebContext().getHttpServletRequest();
}
//获取Response
public HttpServletResponse getHttpServletResponse() {
return getWebContext().getHttpServletResponse();
}
//获取sesion id
public String getSessionId(){
return getSession().getId();
}
//写入sesion
public void setSession(String name,Object objct){
getSession().setAttribute(name, objct);
}
//写入清除sesion
public void deleteSession(String name){
getSession().removeAttribute(name);
}
//获取 getApplicationContext
public ApplicationContext getApplicationContext(){
return WebApplicationContextUtils.getWebApplicationContext(getWebContext().getServletContext());
}
//获取 spring 注入
public Object getBean(String key){
return getApplicationContext().getBean(key);
}
}
5.DwrMethod类
[java]
public class DwrMethod extends Dwr{
UtilService utilService = (UtilService) super.getBean("utilService");
public String isNotRep(String code) throws Exception{
if(code!=null && !"".equals(code)){
return this.utilService.isNotRep("from TblCgDistrict t where t.isDele=0 and t.code="+code); 补充:软件开发 , Java ,