日期:2014-05-16  浏览次数:22570 次

dwr js未定義 - Web 开发 / Ajax
代碼不多 3段 有勞各位父老鄉親了

web.xml

<servlet>
  <servlet-name>dwrServlet</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>dwrServlet</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

dwr.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
  "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN"
  "http://getahead.org/dwr/dwr30.dtd">
<dwr>
<allow>
<create creator="new" javascript="getPower">
<param name="class" value="com.taiyang.dwr.getPower" ></param>
</create>
</allow>
</dwr>

xx.jsp頁面
<script type="text/javascript"
src="<%=request.getContextPath()%>/dwr/engine.js"></script>
<script type="text/javascript"
src="<%=request.getContextPath()%>/dwr/util.js"></script>
<script type="text/javascript"
src="<%=request.getContextPath()%>/dwr/interface/getPower.js"></script>

<script type="text/javascript">
function _select() {
getPower.getP();
}
  </script>

网页错误详细信息

用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
时间戳: Thu, 12 Jan 2012 07:43:30 UTC


消息: 'getPower' 未定义
行: 52
字符: 2
代码: 0
URI: http://127.0.0.1:8888/iptms/sys/user/power.do



------解决方案--------------------
消息: 'getPower' 未定义
可能:
1、js引用路径错误,src="<%=request.getContextPath()%>/dwr/interface/getPower.js"
2、dwr未正常引用