Dwr入门例子(初学者用的)
Dwr用了一段时间了,这会儿蛮写个简单的入门示例~
一个小小的public写成private的错误,找了半天,郁闷~
另外碰到的两个问题:
1.org.directwebremoting.extend.MarshallException: Error marshalling com.freeStyle.dwr.bean.User
解决:配置在dwr.xml的<convert >标签下的Bean如果添加了某有参数的构造器,需得再加个无参数构造器。
????????? 如:<convert match="com.freeStyle.dwr.bean.User" converter="bean" />
2.Probably not an issue: org.jdom.Document is not available so the jdom converter will not load. This is only an problem if you wanted to use it.
解决:引入jdom.jar
?
附件例子,含以下dwr基本功能:
???????? 1.jsp页面传普通参数
?????????2.对象参数到后台
?????????3.从后台取对象列表
?
public String submitForm1(String id, String name) {return "submitForm1: id=" + id + ",name=" + name;}public String submitForm2(User user) {return "submitForm2: id=" + user.getId() + ",name=" + user.getName();}public List<User> getList() {List<User> list = new ArrayList<User>();for (int i = 0; i < 3; i++) {list.add(new User("id" + i, "name" + i));}return list;}
?