DWR 例子 -填充 select
<%@ page language="java" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'dwrTest2.jsp' starting page</title>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="<%=path %>/dwrjs/util.js"></script>
<script type="text/javascript" src="<%=path %>/dwrjs/engine.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/dwr/interface/testDwrService.js"></script>
<script type="text/javascript">
function showSelect(){
var svalue = DWRUtil.getValue("hiddenId");
//alert('param = ' + svalue);
testDwrService.returnSelect(svalue,function(data){
DWRUtil.removeAllOptions('selectId');
DWRUtil.addOptions('selectId',data);
});
}
</script>
</head>
<body style="margin-left: 300px">
This is my JSP page. <br>
<form action="#" method="post" name="frm">
<input type="button" value="Button" onclick="showSelect()"/>
<input type="hidden" id="hiddenId" value="selectValue">
<select id="selectId">
</select>
</form>
</body>
</html>
package com.dwr;
import java.util.List;
public class TestDwrService2 {
public String[] returnSelect(String sValue){
System.out.println("returnSelect sValue : "+ sValue);
String[] opsArray = new String[3];
opsArray[0] = "选项 1";
opsArray[1] = "选项 2";
opsArray[2] = "选项 3";
return opsArray;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="new" javascript="testDwrService">
<param name="class" value="com.dwr.TestDwrService2" />
</create>
</allow>
</dwr>
<!-- 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>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>ExcelServlet</servlet-name>
<servlet-class>com.excel.ExcelServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>