Note that there are some explanatory texts on larger screens.

plurals
  1. POException : "No adapter for handler. Does your handler implement a supported interface like controller?"
    text
    copied!<p>I'm trying to validate a simple form in JSP with Spring and Hibernate using <a href="http://sourceforge.net/projects/hibernate/files/hibernate-validator/4.0.2.GA/hibernate-validator-4.0.2.GA-dist.zip/download?use_mirror=nchc" rel="nofollow">HibernateValidator</a>. The JSP page Temp.jsp is as follows (the url pttern in web.xml is <code>*.htm</code>).</p> <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8" %&gt; &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt; &lt;%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %&gt; &lt;form:form method="post" action="Temp.htm" commandName="validationForm"&gt; &lt;!--validationForm is a model class--&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;User Name:&lt;font color="red"&gt;&lt;form:errors path="userName" /&gt;&lt;/font&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;form:input path="userName" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Age:&lt;font color="red"&gt;&lt;form:errors path="age" /&gt;&lt;/font&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;form:input path="age" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Password:&lt;font color="red"&gt;&lt;form:errors path="password" /&gt;&lt;/font&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;form:password path="password" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form:form&gt; </code></pre> <p>The class <code>validationForm</code> is as follows.</p> <pre><code>package validators; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.format.annotation.NumberFormat; import org.springframework.format.annotation.NumberFormat.Style; final public class ValidationForm { @NotEmpty @Size(min = 1, max = 20) private String userName; @NotNull @NumberFormat(style = Style.NUMBER) @Min(1) @Max(110) private Integer age; @NotEmpty(message = "Password must not be blank.") @Size(min = 1, max = 10, message = "Password must between 1 to 10 Characters.") private String password; public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return userName; } public void setAge(Integer age) { this.age = age; } public Integer getAge() { return age; } public void setPassword(String password) { this.password = password; } public String getPassword() { return password; } } </code></pre> <p>and the <code>Controller</code> class where the validation should be processed is as follows (I'm using <code>SimpleFormController</code>).</p> <pre><code>package controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; import usebeans.TempService; import validators.ValidationForm; @SuppressWarnings("deprecation") final public class Temp extends SimpleFormController { private TempService tempService=null; public Temp() { //setCommandClass(Temp.class); //setSuccessView("Temp"); //setFormView("Temp"); setCommandClass(ValidationForm.class); //Still not working. setCommandName("validationForm"); } public void setTempService(TempService tempService) { this.tempService = tempService; } @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { ModelAndView mv=new ModelAndView(); ValidationForm validationForm=(ValidationForm) command; tempService.add(validationForm); return mv; } @Override protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { ModelAndView mv=new ModelAndView(); return mv; } } </code></pre> <p>In <code>dispatcher-servlet</code>, I have added the following.</p> <pre><code>&lt;bean id="tempService" class="usebeans.TempServiceImpl" /&gt; &lt;bean name="/Temp.htm" class="controller.Temp" p:tempService-ref="tempService" p:formView="Temp" p:successView="Temp" /&gt; </code></pre> <p>Also tried adding the following bean still there is no luck.</p> <pre><code>&lt;bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/&gt; </code></pre> <p>Where the <code>TempService</code> interface is as follows.</p> <pre><code>package usebeans; import validators.ValidationForm; public interface TempService { public void add(ValidationForm validationForm); } </code></pre> <p>and following is the <code>TempServiceImpl</code> class.</p> <pre><code>package usebeans; import validators.ValidationForm; final public class TempServiceImpl implements TempService { public void add(ValidationForm validationForm) { System.out.println("Message"); } } </code></pre> <p>Although the class <code>TempServiceImpl</code> implements the <code>TempService</code> interface, I'm getting the following exception.</p> <pre><code>javax.servlet.ServletException: No adapter for handler [usebeans.TempServiceImpl@ab3cba]: Does your handler implement a supported interface like Controller? at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:982) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:770) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555) at java.lang.Thread.run(Thread.java:619) </code></pre> <hr> <p><strong>Edit :</strong></p> <p>Although I'm following what is explained <a href="http://www.vaannila.com/spring/spring-simple-form-controller-1.html" rel="nofollow">here</a>, the problem remains and I'm getting the same exception as mentioned above. What configuration settings am I missing here. It may be in the <code>dispatcher-servlet.xml</code> file. The entire <code>dispatcher-servlet.xml</code> file is as follows.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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"&gt; &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&gt; &lt;bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /&gt; &lt;bean id="tempService" class="usebeans.TempServiceImpl" /&gt; &lt;bean name="/Temp.htm" class="controller.Temp" p:tempService-ref="tempService" p:formView="Temp" p:successView="Temp" /&gt; &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt; &lt;property name="mappings"&gt; &lt;props&gt; &lt;prop key="index.htm"&gt;indexController&lt;/prop&gt; &lt;prop key="Temp.htm"&gt;tempService&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /&gt; //The index controller. &lt;bean name="indexController" class="org.springframework.web.servlet.mvc.ParameterizableViewController" p:viewName="index" /&gt; &lt;/beans&gt; </code></pre> <p>I don't have any precise idea about that exception being thrown. Can you figure it out why is that exception being thrown? What configuration settings or something else am I missing here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload