CouponServiceImpl.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.*.Forum;
public class CouponServiceImpl implements ICouponService {
private ICouponDao dao;
public void setDao(ICouponDao dao) {
this.dao = dao;
}
public List getGoodsInfo(String name){
System.out.println("name="+name);
//List 里Map或Bean都可以jsp页面不用改动
List results = new ArrayList();
Forum forum = new Forum();
/*Map map = new HashMap();
map.put("fourmId", 1);
map.put("fourmName", name);*/
forum.setForumId(1);
forum.setForumName(name);
results.add(forum);
Forum forum1 = new Forum();
/*Map map1 = new HashMap();
map1.put("fourmId", 2);
map1.put("fourmName", "很好");*/
forum1.setForumId(2);
forum1.setForumName("牛");
results.add(forum1);
return results;
}
}
dwr.xml
<dwr>
<allow>
<create creator="spring" javascript="Goods">
<!--这里配置spring Bean id-->
<param name="beanName" value="couponService" />
</create>
<!--bean 一定要配置-->
<convert match="com.*.Forum" converter="bean">
</convert>
</allow>
</dwr>
spring.xml
<bean id="couponService" class="com.*.CouponServiceImpl">
<property name="dao">
<ref local="couponDao"/>
</property>
</bean>
*.jsp
<script type='text/javascript' src='<%=path %>/dwr/interface/Goods.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/util.js'></script>
<script type="text/javascript">
function getGoods(){
var userName = ${"username"}.value;
Goods.getGoodsInfo(userName,showName);
}
function showName(data){
alert(data.length);
for(var i=0;i<data.length;i++){
alert(data[i].forumName);
}
DWRUtil.addOptions('forumsel', data,'fourmId','forumName');
}
</script>
</head>
<body>
<input type="text" name="username" value="" onblur="getGoods()" /><div id="userMsg"></div>
<select name="forumsel" id="forumsel">
</select>
</body>
分享到:
相关推荐
List<User> userList = new ArrayList<>(); // populate the list return userList; } } ``` 在DWR配置中,你需要声明`MyAction`类以及`selectUserData`方法,这样DWR才能知道如何调用它: ```xml <dwr-engine...
HelloDwr.sendListNoGeneric(List<Person>); ]]> </signatures> </dwr> ``` 三、实现类和页面JS 在lee包中,创建HelloDwr类,用于提供远程方法: ```java public class HelloDwr { // 第一个简单的hello方法 ...
<filter-name>DWR Filter</filter-name> <filter-class>org.directwebremoting.servlet.DwrFilter</filter-class> </filter> <filter-mapping> <filter-name>DWR Filter</filter-name> <url-pattern>/dwr/*</...
例如,Java方法返回一个`List<JavaBean>`,DWR会将其转换为JavaScript数组,每个元素都是对应的JavaScript对象。你可以在JavaScript中使用`for`循环遍历并访问这些对象。 此外,DWR提供了错误处理、安全控制、缓存...
public List<SelectItem> getDependentOptions(String parentOption) { return service.getDependentOptionsByParent(parentOption); } } ``` 在`getDependentOptions`方法中,我们根据`parentOption`查询数据库...
private static Map<Integer, List<Person>> persons = new HashMap<>(); // 初始化数据 static { for (int i = 0; i < 10; i++) { Org org = new Org(); org.setId(i); org.setName("省份" + i); orgs.put...
public String dwrtest(String a, String b, List<String> s,Map<String,String>map) { StringBuilder strbui = new StringBuilder(); strbui.append(a).append(",").append(b).append(","); for (String str ...
<script type="text/javascript" src="/dwrtest/dwr/engine.js"></script> <script type="text/javascript" src="/dwrtest/dwr/util.js"></script> <script type="text/javascript"> function testFunction() { ...
<dwr:remote-method name="doSomething" return="java.lang.String"> <dwr:param name="input" type="java.lang.String"/> </dwr:remote-method> </dwr:direct> ``` ### 整合中常见的问题及解决方法 #### 使用...
<script type="text/javascript" src="/dwr/interface/UserService.js"></script> <script type="text/javascript"> UserService.getUserList(function(userList) { // 处理返回的用户列表 for (var i = 0; i ...
<script type="text/javascript" src="dwr/interface/citys.js"></script> <script type="text/javascript" src="dwr/engine.js"></script> ``` 6. **编写JavaScript代码**:现在可以在JavaScript中直接调用服务器...
<script type="text/javascript" src="/dwr/interface/UserController.js"></script> <script type="text/javascript" src="/dwr/engine.js"></script> <script type="text/javascript"> UserController....
List<String> list = new ArrayList<>(); list.add("Hello"); list.add("Say"); list.add("张三"); return list; } ``` 客户端调用: ```javascript $("#btn2").click(function () { HelloWorld.getMsg({ ...
List<MyClass> list = new ArrayList<>(); // 填充数据... return list; } ``` `MyClass`应包含合适的getter和setter方法,以便DWR可以自动转换其为JSON格式。 3. **JavaScript调用**: 在客户端,你可以通过...
<creator id="script" class="uk.ltd.getahead.dwr.create.ScriptedCreator"/>这种类型的creator采用BSF执行脚本语言并返回bean.例如 <allow> ... <create creator="script" javascript="EmailValidator"> <param...
如果Java方法的参数是一个列表,例如`public String getSize(List<String> data)`,可以通过以下方式实现: - **步骤1:定义Java类** ```java public class DwrTest { public String getSize(List<String> data)...
PageResult<Company> page = new PageResult<>(); List<Company> list = companyDao.getAll(); page.setData(list); page.setRowCount(list.size()); return page; } } ``` 以上就是关于Extjs与DWR结合使用的...
- 利用Spring的IoC容器管理DWR相关的Bean。 - 通过Hibernate查询数据库获取匹配项。 ### 自动补全的具体实现步骤 #### 步骤一:配置DWR环境 1. 添加DWR相关依赖到项目中。 2. 配置DWR的servlet和filter,使其能够...