DWR例子

首先在创建DWR例子需要下载DWR.JAR包,先放在博客中下载
然后需要在WEB-INF下面创建一个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>
      <!-- javascript:这个类的JS名称 -->
    <create creator="new" javascript="MyDwr">
      <!-- value:类路径 -->
      <param name="class" value="com.yl.dwr.MyDwr"/>
    </create>
  </allow>
</dwr>


WEB.XML
<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>



MyDwr.java
import uk.ltd.getahead.dwr.WebContext;
import uk.ltd.getahead.dwr.WebContextFactory;

public class MyDwr 
{
	public String getInclude()
	{
		WebContext web = WebContextFactory.get();
		try {
			return web.forwardToString("/Forward.html");
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}


<script type='text/javascript' src='/YL/dwr/interface/MyDwr.js'></script>
   	<script type='text/javascript' src='/YL/dwr/engine.js'></script>
	<script type='text/javascript' src='/YL/dwr/util.js'></script>

	<script>
	  function forward() 
	  {
	    MyDwr.getInclude(function(data) 
	    {
	      dwr.util.setValue("forward", data, { escapeHtml:false });
	    });
	  }
	</script>



你可能感兴趣的:(JavaScript,java,Web,xml,DWR)