NutzCN Logo
问答 求指导,dwr框架在nutz中如何引用
发布于 2710天前 作者 qq_c01e2ba8 1471 次浏览 复制 上一个帖子 下一个帖子
标签:

dwr框架在nutz中如何引用,

38 回复

在pom.xml中引入了dwr的jar包,配置了web.xml文件,在webINF下新建了dwr.xml文件,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" >
			<param name="class" value="com.wonders.tdsc.workflow.DwrTest"/>
		</create>
	</allow>
</dwr>

新建java类,如下:

package com.wonders.tdsc.workflow;

public class DwrTest {
	
	public String sayHello(String name){  
        System.out.println("hello "+name);  
        return "hello "+name;  
    }  
	
}

jsp页面如下:

<%@page contentType="text/html" pageEncoding="UTF-8"%>  
<!DOCTYPE html>  
<html>  
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
        <title>JSP Page</title>  
        <script type='text/javascript' src="dwr/engine.js"></script>
        <script type='text/javascript' src='dwr/util.js'></script>  
        <script src="dwr/interface/DwrTest.js"></script>  
          
        <script>  
            Hello.sayHello("张三");  
        </script>  
    </head>  
    <body>  
        <h1>Hello World!</h1>  
    </body>  
</html>  

引用什么?需要用到nutz的什么?

有见nutz有一个dwr的框架,我这样写,在浏览器中也没有访问到,不知道是什么问题

"nutz有一个dwr的框架" ??? 哪里? 发个链接看看??

错了,是插件

web.xml没配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>  
         
        <load-on-startup>1</load-on-startup>  
    </servlet>  
  
    <servlet-mapping>  
        <servlet-name>dwr-invoker</servlet-name>  
        <url-pattern>/dwr/*</url-pattern>  
    </servlet-mapping>  
  <mime-mapping>

是报错还是怎样?页面找不到?js找不到?

页面找不到,http://localhost:8080/trademanage/DwrTest/dwrTest.jsp,地址这样写对吗

那你把jsp放在啥文件路径; ?

在webapp下,与webinf并列

现在可以访问到页面了。。。

但是js hello找不到,浏览器错误如下

Uncaught ReferenceError: Hello is not defined
    at dwrTest.jsp:12
(anonymous) @ dwrTest.jsp:12
<script src="${base}/dwr/interface/DwrTest.js"></script>

封装了ctx,如下:<c:set var="ctx" value="${pageContext.request.contextPath}"/>,在jsp页面引用的时候加了ctx,还是不行,如下:

<%@ page language="java" contentType="text/html; charset=utf-8"  pageEncoding="utf-8"%>
<%@ include file="/commonjsp/taglibs.jsp" %>
<!DOCTYPE html>  
<html>  
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
        <title>JSP Page</title>  
        <script type='text/javascript' src="${ctx}/dwr/engine.js"></script>
        <script type='text/javascript' src='${ctx}/dwr/util.js'></script>  
        <script src="${ctx}/dwr/interface/DwrTest.js"></script>  
          
        <script>  
            Hello.sayHello("张三");  
        </script>  
    </head>  
    <body>  
        <h1>Hello World!</h1>  
    </body>  
</html>  

项目 是maven,直接在pom中导入了jar包,没有实际向项目中导入jar,,这样可以直接访问dwr.jar中的内容吗

/dwr/interface/DwrTest.js 是不是404了?

恩,那3个js都没有获取到

整个web.xml贴一下

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>jygl</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <session-config>
    <session-timeout>15</session-timeout>
  </session-config>
  <filter>
    <filter-name>nutz</filter-name>
    <filter-class>org.nutz.mvc.NutFilter</filter-class>
    <init-param>
      <param-name>modules</param-name>
      <param-value>com.wonders.MainModule</param-value>
    </init-param>
    <init-param>
      <param-name>ignore</param-name>
      <param-value>^(.+[.])(jsp|png|gif|jpg|js|css|jspx|jpeg|html|xml|htm|doc|docx)$</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>nutz</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>
  <servlet>
    <description></description>
    <display-name>SaveDreamOffice</display-name>
    <servlet-name>SaveDreamOffice</servlet-name>
    <servlet-class>com.wonders.tiles.dreamoffice.SaveDreamOfficeAt</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>SaveDreamOffice</servlet-name>
    <url-pattern>/SaveDreamOffice</url-pattern>
  </servlet-mapping>
  <servlet>
    <description></description>
    <display-name>OpenDreamOffice</display-name>
    <servlet-name>OpenDreamOffice</servlet-name>
    <servlet-class>com.wonders.tiles.dreamoffice.OpenDreamOfficeAt</servlet-class>
  </servlet> 
  <servlet-mapping>
    <servlet-name>OpenDreamOffice</servlet-name>
    <url-pattern>/OpenDreamOffice</url-pattern>
  </servlet-mapping>
  <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>  
         
        <load-on-startup>1</load-on-startup>  
    </servlet>  
  
    <servlet-mapping>  
        <servlet-name>dwr-invoker</servlet-name>  
        <url-pattern>/dwr/*</url-pattern>  
    </servlet-mapping>  
  <mime-mapping>
    <extension>doc</extension>
    <mime-type>application/msword</mime-type>
  </mime-mapping>
  <mime-mapping>
  	<extension>ppt</extension>
  	<mime-type>application/ms-powerpoint</mime-type>
  </mime-mapping>
  <mime-mapping>
    <extension>xls</extension>
    <mime-type>application/ms-excel</mime-type>
  </mime-mapping>
 <!--  <listener>
	<listener-class>com.wonders.socket.SocketListener</listener-class>
  </listener> -->
  
</web-app>

恩, 连/dwr/engine.js都找不到的话, debug一下DwrServlet吧, 也许就没进DwrServlet

DwrServlet在哪里。。。

有类名还找不到类??

确实没有进去到那个方法

是dwr.xml配置的不对吗

没进哪个方法?

这个方法

package com.wonders.tdsc.workflow;

public class DwrTest {
	
	public String sayHello(String name){  
        System.out.println("hello "+name);  
        return "hello "+name;  
    }  
	
}

后台报错

严重: Servlet [dwr-invoker] in web application [/trademanage] threw load() exception
java.lang.ClassNotFoundException: org.directwebremoting.servlet.DwrServlet
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1139)
	at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:518)
	at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:499)
	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1102)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4996)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1092)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1834)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

原来dwr依赖都没加

		<dependency>
			<groupId>org.directwebremoting</groupId>
			<artifactId>dwr</artifactId>
			<version>3.0.M1</version>
		</dependency>

pom.xml中有的

<dependency>
	    	<groupId>org.directwebremoting</groupId>
	    	<artifactId>dwr</artifactId>
	    	<version>3.0.2-RELEASE</version>
	  	</dependency>

我把dwr.jar放在了lib下,后台不报错了,页面上只提示hello找不到

Uncaught ReferenceError: Hello is not defined
    at dwrTest.jsp:20
(anonymous) @ dwrTest.jsp:20

maven项目,你放到lib干毛线?

我就试试。。。

刚才我删掉重新运行了一下,没有那个异常了,只有hello方法找不到

问题已经解决了。。。

方法名写错了。。。。心里一万头草泥马在奔腾。。

添加回复
请先登陆
回到顶部