I have created a Spring DWR integration referring from here.
When I run the project I get a pop up "NOT FOUND" in the browser the response for dwrService.js is not found. Engine.js and util.js are loaded correctly.
Request: `http://localhost:8080/HelloWorldSpring3/dwr/interface/dwrService.js`
Response: "404 Not Found"
The message in the console is
an 10, 2014 4:12:31 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/HelloWorldSpring3/forms/dwr/interface/dwrService.js] in DispatcherServlet with name 'dispatcher'
Jan 10, 2014 4:14:24 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/HelloWorldSpring3/forms/dwr/dwr/interface/dwrService.js] in DispatcherServlet with name 'dispatcher'
Why the request for dwrService.js is going for the dispatcher servlet?
Below are my config files and controller and jsp
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
<display-name>Comet</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Mapping for DWR -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/forms/dwr/*</url-pattern>
</servlet-mapping>
<!-- Mapping for MVC -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/forms/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
dwr-Context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
<dwr:annotation-config />
<dwr:annotation-scan base-package="net.roseindia.controllers" scanDataTransferObject="true" scanRemoteProxy="true" />
<dwr:url-mapping />
<dwr:controller id="dwrController" debug="true">
<dwr:config-param name="activeReverseAjaxEnabled" value="true"/>
</dwr:controller>
</beans>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="net.roseindia.controllers" />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<import resource="file:**/WebContent/WEB-INF/dwr-context.xml" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
JSP
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Spring MVC - DWR Integration Tutorial</title>
<script type='text/javascript' src="${pageContext.request.contextPath}/dwr/engine.js"></script>
<script type='text/javascript' src="${pageContext.request.contextPath}/dwr/util.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/dwr/interface/dwrService.js"></script>
</head>
<body>
<h3>Spring MVC - DWR Integration Tutorial</h3>
<h4>AJAX version</h4>
<script type="text/javascript">
// Retrieves the matching value
// Delegates to the dwrService
function add() {
// Retrieve value of text inputs
var operand1 = dwr.util.getValue("inputNumber1");
var operand2 = dwr.util.getValue("inputNumber2");
// Pass two numbers, a callback function, and error function
dwrService.add(operand1, operand2, {
callback : handleAddSuccess,
errorHandler : handleAddError
});
}
// data contains the returned value
function handleAddSuccess(data) {
// Assigns data to result id
dwr.util.setValue("sum", data);
}
function handleAddError() {
// Show a popup message
alert("We can't add those values!");
}
</script>
Demo 1
<div style="border: 1px solid #ccc; width: 250px;">
Add Two Numbers: <br/>
<input id="inputNumber1" type="text" size="5"> +
<input id="inputNumber2" type="text" size="5">
<input type="submit" value="Add" onclick="add()" /> <br/>
Sum: <span id="sum">(Result will be shown here)</span>
</div>
</body>
</html>
What am i doing wrong here?