Search code examples
postdwr

DWR using get / post url


I am using DWR for one of my application. I have setup the environment and clear about how to make call to Java functions using the ClassName.method() approach. But I want to use jsonp style approach mentioned here http://directwebremoting.org/dwr/introduction/remoting_options.html.

I tried creating sample application and run on tomcat. But I was unable to get any result from server. It was saying 404.

This is my call:

         $.post("/DWRDemo/dwr/jsonp/Demo/sayHello/" + name, { },
          function(data) {
              dwr.util.setValue("demoReply", data.reply);
          }, "jsonp"); 
      } 

where

DWRDemo: Application name

Demo: class name

sayHello : method name

=====================================================================

dwr.xml

<create creator="new" javascript="Demo">
    <param name="class" value="org.getahead.dwrdemo.simpletext.Demo"/>
</create>

=====================================================================

web.xml

      <servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <display-name>DWR Servlet</display-name>
    <description>Direct Web Remoter Servlet</description>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    <init-param>
     <param-name>jsonpEnabled</param-name>
     <param-value>true</param-value>
    </init-param>

     <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> 

=====================================================================

And I have included the required .js files in my html

====================================================================

Is there any other configuration that I am missing.

Appreciate your help.

Regards,

Ronak


Solution

  • I have found the resolution. Actually, I was using DWR.jar (version 2.7). But looks like it does not support servlet call. I tried with DWR.jar (version 3.0) and it worked straight away.