DWR使用步骤

 DWR使用步骤;
1.导入dwr.jar包,在web.xml文件里面配制如下:

              <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>
2.写java文件如下:
package com.softeem.dwr;
 
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.softeem.config.DataSourceFactory;
import com.softeem.dao.BookInfoDao;
import com.softeem.dto.CityDto;
 
public class GetInfo {
       Map<String,String> map = new HashMap<String,String>();
      
       public Map getCities(String id){
              Connection conn = null;
              try {
                     conn = DataSourceFactory.getBasicDataSource().getConnection();
                     BookInfoDao dao = new BookInfoDao(conn);
                     List<CityDto> list = dao.findCity(Integer.parseInt(id));
                     for(int i = 0;i < list.size();i++){
                            map.put(new Integer(list.get(i).getId()).toString(),list.get(i).getCity());
                     }
              } catch (SQLException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
              }
              return map;
       }
      
       public CityDto getCityDto(){
              CityDto dto = new CityDto();
              dto.setId(2);
              dto.setCity("hanwan");
              return dto;
       }
 
}
 
 
 
package com.softeem.dwr;
 
public class Service {
       public String sayHello(String name){
              return "hello " + name;
       }
}
      
3.增加配制文件dwr.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<dwr>
       <allow>
              <create creator="new" javascript="service">
                     <param name="class" value="com.softeem.dwr.Service" />
              </create>
              <create creator="new" javascript="getInfo">
                     <param name="class" value="com.softeem.dwr.GetInfo" />
              </create>
              <convert converter="bean" match="com.softeem.dto.CityDto">
                     <param name="include" value="city,id" />
              </convert>
       </allow>
</dwr>
 
4.在jsp文件里面加入代码往下:
 
 
阅读更多
下一篇在jsp中把相对路径变为绝对路径的方法
想对作者说点什么? 我来说一句

DWR使用步骤DWR使用步骤

2009年07月17日 60KB 下载

没有更多推荐了,返回首页

关闭
关闭