<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nitish Sati on Medium]]></title>
        <description><![CDATA[Stories by Nitish Sati on Medium]]></description>
        <link>https://medium.com/@nitish.sati?source=rss-21f69107fc20------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Nitish Sati on Medium</title>
            <link>https://medium.com/@nitish.sati?source=rss-21f69107fc20------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 03:23:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nitish.sati/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Web Application development with DWR(direct web remoting) and Spring Boot]]></title>
            <link>https://medium.com/xebia-engineering/web-application-development-with-dwr-direct-web-remoting-and-spring-boot-b7cde7747bd2?source=rss-21f69107fc20------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7cde7747bd2</guid>
            <category><![CDATA[ajax]]></category>
            <dc:creator><![CDATA[Nitish Sati]]></dc:creator>
            <pubDate>Tue, 20 Jul 2021 05:42:24 GMT</pubDate>
            <atom:updated>2021-07-20T05:42:24.917Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*EH-jAjnJ_MuEQafO" /></figure><p>DWR is a Java library which allows JavaScript functions to call Java methods and Java methods to call JavaScript functions(reverse ajax). It dynamically generates the JavaScript library of service class or servlet class to allow web browsers to call java code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/0*03O1d0dPrAxU5n4d" /></figure><p><strong>DWR has two main parts:</strong></p><ol><li>Java servlet or Java service which is running on the server that accepts requests and sends responses back to the client.</li><li>JavaScript library which is running on the web browser that sends requests to the server and receives the response to update the page.</li></ol><p>It provides integration with servlets and popular frameworks such as Spring, Hibernate, Struts and others. It is open source.</p><p>Having a basic understanding of DWR, let us move to the code area where we will build web applications using spring boot and DWR.</p><p><strong>Following are steps for configuring DWR in spring boot project</strong></p><ol><li><em>In the first step create a spring boot project with the following dependency.</em></li></ol><pre>&lt;dependency&gt;</pre><pre>&lt;groupId&gt;org.directwebremoting&lt;/groupId&gt;</pre><pre>&lt;artifactId&gt;dwr&lt;/artifactId&gt;</pre><pre>&lt;version&gt;3.0.2-RELEASE&lt;/version&gt;</pre><pre>&lt;/dependency&gt;</pre><p>2. Add spring.xml to the resource folder to configure dwr scanning.</p><pre>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot;?&gt;</pre><pre>&lt;beans xmlns=”http://www.springframework.org/schema/beans&quot;</pre><pre>xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&quot;</pre><pre>xmlns:dwr=”http://www.directwebremoting.org/schema/spring-dwr&quot;</pre><pre>xsi:schemaLocation=”http://www.springframework.org/schema/beans <a href="http://www.springframework.org/schema/beans/spring-beans.xsd">http://www.springframework.org/schema/beans/spring-beans.xsd</a></pre><pre><a href="http://www.directwebremoting.org/schema/spring-dwr">http://www.directwebremoting.org/schema/spring-dwr</a> http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd&quot;&gt;</pre><pre>&lt;dwr:annotation-config/&gt;</pre><pre>&lt;dwr:annotation-scan scanRemoteProxy=”false” base-package=”<em>com.dwr.test</em>”/&gt;</pre><pre>&lt;dwr:configuration/&gt;</pre><pre>&lt;/beans&gt;</pre><p>3. Configure spring boot startup main class to load spring.xml</p><pre>@SpringBootApplication</pre><pre>@ImportResource(“classpath*:spring.xml”)</pre><pre>public class DwrDemo {</pre><pre>public static void main(String[] args) {</pre><pre>SpringApplication.run(DwrDemo.class, args);</pre><pre>}</pre><pre>}</pre><p>4. If the project is based on servlets then dwr.xml is used for configuration but in case of spring boot we need to add configuration with java code.</p><pre>@Configuration</pre><pre>public class DwrConfig {</pre><pre>/**</pre><pre>* Join the DWR servlet, which is equivalent to configuring in xml</pre><pre>* @return</pre><pre>*/</pre><pre>@Bean</pre><pre>public ServletRegistrationBean servletRegistrationBean() {</pre><pre>DwrSpringServlet servlet = new DwrSpringServlet();</pre><pre>ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, “/dwr/*”);</pre><pre>// Set to true to enable DWR to debug and enter the test page.</pre><pre>registrationBean.addInitParameter(“debug”, “true”);</pre><pre>//pollAndCometEnabled set to true to increase the loadability of the server, although DWR has a mechanism to protect the server from overload.</pre><pre>registrationBean.addInitParameter(“pollAndCometEnabled”, “true”);</pre><pre>registrationBean.addInitParameter(“activeReverseAjaxEnabled”, “true”);</pre><pre>registrationBean.addInitParameter(“maxWaitAfterWrite”, “60”);</pre><pre>return registrationBean;</pre><pre>}</pre><pre>}</pre><p>5. In the final step we have to create a service class which will be used for writing business logic.</p><pre>import java.util.LinkedList;</pre><pre>import java.util.List;</pre><pre>import org.directwebremoting.annotations.RemoteMethod;</pre><pre>import org.directwebremoting.annotations.RemoteProxy;</pre><pre>import org.springframework.stereotype.Service;</pre><pre>@Service</pre><pre>@RemoteProxy // The annotation of spring is equivalent to exposing the service</pre><pre>public class Message {</pre><pre>@RemoteMethod</pre><pre>public List&lt;String&gt; getOptionList() {</pre><pre>List&lt;String&gt; option = new LinkedList&lt;&gt;();</pre><pre>for (int i = 0; i &lt; 5; i++)</pre><pre>option.add(“field_” + i);</pre><pre>return option;</pre><pre>}</pre><pre>}</pre><p>6. Final step integration with html</p><pre>&lt;!DOCTYPE html&gt;</pre><pre>&lt;html&gt;</pre><pre>&lt;head&gt;</pre><pre>&lt;title&gt;DWR test&lt;/title&gt;</pre><pre>&lt;meta charset=<em>&quot;utf-8&quot;</em>&gt;</pre><pre>&lt;meta name=<em>&quot;viewport&quot;</em> content=<em>&quot;width=device-width, initial-scale=1&quot;</em>&gt;</pre><pre>&lt;link rel=<em>&quot;stylesheet&quot;</em></pre><pre>href=<em>&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css&quot;</em>&gt;</pre><pre>&lt;script</pre><pre>src=<em>&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;</em>&gt;&lt;/script&gt;</pre><pre>&lt;script</pre><pre>src=<em>&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js&quot;</em>&gt;&lt;/script&gt;</pre><pre>&lt;script type=<em>&#39;text/javascript&#39;</em> src=<em>&#39;/dwr/engine.js&#39;</em>&gt;&lt;/script&gt;</pre><pre>&lt;script type=<em>&#39;text/javascript&#39;</em> src=<em>&#39;/dwr/interface/Message.js&#39;</em>&gt;&lt;/script&gt;</pre><pre>&lt;script type=<em>&quot;text/javascript&quot;</em> src=<em>&quot;/dwr/util.js&quot;</em>&gt;&lt;/script&gt;</pre><pre>&lt;script&gt;</pre><pre>$(document).ready(<strong>function</strong>() {</pre><pre>dwr.util.useLoadingMessage();</pre><pre>update();</pre><pre>});</pre><pre><strong>function</strong> update() {</pre><pre>Message.getMessage(<strong>function</strong>(data) {</pre><pre>dwr.util.setValue(&quot;divResponse&quot;, data);</pre><pre>dwr.util.setValue(&quot;text&quot;, data);</pre><pre>});</pre><pre>getList();</pre><pre>}</pre><pre><strong>function</strong> getList() {</pre><pre>Message.getOptionList(<strong>function</strong>(data) {</pre><pre>fillDropDown(data);</pre><pre>fillWithDwrUtil(data);</pre><pre>});</pre><pre>}</pre><pre><strong>function</strong> fillDropDown(options) {</pre><pre><strong>var</strong> select = document.getElementById(&quot;optionList&quot;);</pre><pre><strong>for</strong> (<strong>var</strong> i = 0; i &lt; options.length; i++) {</pre><pre><strong>var</strong> opt = options[i];</pre><pre><strong>var</strong> el = document.createElement(&quot;option&quot;);</pre><pre>el.textContent = opt;</pre><pre>el.value = opt;</pre><pre>select.appendChild(el);</pre><pre>}</pre><pre>}</pre><pre><strong>function</strong> fillWithDwrUtil(data) {</pre><pre>dwr.util.removeAllOptions(&quot;optionList2&quot;);</pre><pre>dwr.util.addOptions(&quot;optionList2&quot;, data);</pre><pre>}</pre><pre>&lt;/script&gt;</pre><pre>&lt;/head&gt;</pre><pre>&lt;body&gt;</pre><pre>&lt;div class=<em>&quot;container&quot;</em>&gt;</pre><pre>&lt;div class=<em>&quot;alert alert-success&quot;</em>&gt;</pre><pre>&lt;center&gt;</pre><pre>&lt;strong&gt;Web App demo of DWR&lt;/strong&gt;</pre><pre>&lt;/center&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;label for=<em>&quot;sel1&quot;</em>&gt;Random message number from server&lt;/label&gt;</pre><pre>&lt;div id=<em>&quot;divResponse&quot;</em> class=<em>&quot;well&quot;</em>&gt;&lt;/div&gt;</pre><pre>&lt;div class=<em>&quot;form-group&quot;</em>&gt;</pre><pre>&lt;input id=<em>&quot;text&quot;</em> class=<em>&quot;form-control&quot;</em>&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;h2&gt;Form control: select&lt;/h2&gt;</pre><pre>&lt;p&gt;The form below contains two dropdown menus (select lists):&lt;/p&gt;</pre><pre>&lt;form&gt;</pre><pre>&lt;div class=<em>&quot;form-group&quot;</em>&gt;</pre><pre>&lt;label for=<em>&quot;sel1&quot;</em>&gt;Drop down list using js function&lt;/label&gt; &lt;select</pre><pre>class=<em>&quot;form-control&quot;</em> id=<em>&quot;optionList&quot;</em>&gt;</pre><pre>&lt;/select&gt; &lt;br&gt; &lt;label for=<em>&quot;sel2&quot;</em>&gt;Drop down list using dwr util&lt;/label&gt; &lt;select</pre><pre>class=<em>&quot;form-control&quot;</em> id=<em>&quot;optionList2&quot;</em>&gt;</pre><pre>&lt;/select&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/form&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/body&gt;</pre><pre>&lt;/html&gt;</pre><p>Final result is below:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F0YXwycvUjYV5LKaHHyviA.png" /></figure><p>To know more about dwr, Kindly go to this link <a href="http://directwebremoting.org/dwr/index.html"><em>DWR — Easy Ajax for JAVA</em></a>.</p><p>You can find the full code base at my github repo.</p><p><a href="https://github.com/nitishsati82/dwrtest">GitHub</a></p><p><strong>References:-</strong></p><p><a href="http://directwebremoting.org/dwr/index.html">DWR — Easy Ajax for JAVA</a></p><p><a href="https://dzone.com/articles/direct-web-remoting-tips">DWR article</a></p><p><a href="https://www.programmersought.com/article/8611739802/">DWR Java</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7cde7747bd2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xebia-engineering/web-application-development-with-dwr-direct-web-remoting-and-spring-boot-b7cde7747bd2">Web Application development with DWR(direct web remoting) and Spring Boot</a> was originally published in <a href="https://medium.com/xebia-engineering">Xebia Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>