浏览 1883 次
锁定老帖子 主题:模态窗口DWR调用,填充select
该帖已经被评为隐藏帖
|
|
---|---|
作者 | 正文 |
发表时间:2008-04-01
1.首先新建项目,把dwr.jar拷贝到lib目录 2.添加web.xml代码 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <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> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> </web-app> 3.dwr.xml内容 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd"> <dwr> <allow> <create creator="new" javascript="Test"> <param name="class" value="com.test.Test" /> </create> </allow> </dwr> 4.Test.java内容 package com.test; import java.util.Map; import java.util.TreeMap; /** * @author lhq E-mail:yourgame@163.com * @version 创建时间:2008-4-1 下午09:07:25 */ public class Test { public Map getOptions() { Map map = new TreeMap(); map.put("1", "aa"); map.put("2", "bb"); map.put("3", "cc"); map.put("4", "dd"); map.put("5", "ee"); return map; } } 5.index.jsp内容 <%@ page language="java" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type='text/javascript' src='/dwrselec/dwr/interface/Test.js'></script> <script type='text/javascript' src='/dwrselec/dwr/engine.js'></script> <script type='text/javascript' src='/dwrselec/dwr/util.js'></script> <script type="text/javascript"> function init(){ Test.getOptions(function(data){ dwr.util.removeAllOptions('x'); dwr.util.addOptions('x',{'':'请选择'}); dwr.util.addOptions('x',data); }); } </script> </head> <body> <input type="button" value="showModalDialog()" onclick="window.showModalDialog('a.jsp',window,'dialogWidth:200px;dialogHeight:50px');"> <select id="x" name="x" onchange="alert(this.options[this.selectedIndex].value)"> <option> sdf </option> </select> </body> </html> 6.a.jsp 内容 <%@ page language="java" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type='text/javascript' src='/dwrselec/dwr/interface/Test.js'></script> <script type='text/javascript' src='/dwrselec/dwr/engine.js'></script> <script type='text/javascript' src='/dwrselec/dwr/util.js'></script> <script type="text/javascript"> var s = window.dialogArguments; </script> </head> <body> <input type="button" value="调用父窗口的方法" onclick="s.init();" /> </body> </html> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |