Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 例外情况:;处理程序没有适配器。您的处理程序是否实现了像控制器这样受支持的接口;_Java_Spring_Hibernate_Jsp_Hibernate Validator - Fatal编程技术网

Java 例外情况:;处理程序没有适配器。您的处理程序是否实现了像控制器这样受支持的接口;

Java 例外情况:;处理程序没有适配器。您的处理程序是否实现了像控制器这样受支持的接口;,java,spring,hibernate,jsp,hibernate-validator,Java,Spring,Hibernate,Jsp,Hibernate Validator,我试图使用Spring和Hibernate验证JSP中的一个简单表单。JSP页面Temp.JSP如下所示(web.xml中的url pttern是*.htm) 应该在其中处理验证的Controller类如下(我使用的是SimpleFormController) 在DispatcherServlet中,我添加了以下内容 <bean id="tempService" class="usebeans.TempServiceImpl" /> <bean name="/Temp.htm"

我试图使用Spring和Hibernate验证JSP中的一个简单表单。JSP页面Temp.JSP如下所示(web.xml中的url pttern是
*.htm

应该在其中处理验证的
Controller
类如下(我使用的是
SimpleFormController

在DispatcherServlet中,我添加了以下内容

<bean id="tempService" class="usebeans.TempServiceImpl" />
<bean name="/Temp.htm" class="controller.Temp" p:tempService-ref="tempService" p:formView="Temp" p:successView="Temp" />
下面是
TempServiceImpl

package usebeans;

import validators.ValidationForm;

final public class TempServiceImpl implements TempService
{
    public void add(ValidationForm validationForm)
    {
        System.out.println("Message");
    }
}
尽管类
TempServiceImpl
实现了
TempService
接口,但我得到了以下异常

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)

编辑:

尽管我遵循了解释,但问题仍然存在,我得到了与上面提到的相同的异常。我在这里缺少什么配置设置。它可能位于
dispatcherservlet.xml
文件中。整个
dispatcherservlet.xml
文件如下所示

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;
    }
}
package usebeans;

import validators.ValidationForm;

public interface  TempService
{
    public void add(ValidationForm validationForm);
}
<?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: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">

        <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>    
        <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />


        <bean id="tempService" class="usebeans.TempServiceImpl" />
        <bean name="/Temp.htm" class="controller.Temp" p:tempService-ref="tempService" p:formView="Temp" p:successView="Temp" />


        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="index.htm">indexController</prop>                
                    <prop key="Temp.htm">tempService</prop>                
                </props>
            </property>
        </bean>

        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/jsp/"
              p:suffix=".jsp" />


        //The index controller.

        <bean name="indexController"
              class="org.springframework.web.servlet.mvc.ParameterizableViewController"
              p:viewName="index" />

</beans>

索引控制器
临时服务
//索引控制器。

我不知道会抛出什么异常。你能理解为什么会抛出异常吗?这里缺少什么配置设置或其他内容?

我已经解决了问题,请查找新的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: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">

    <bean
        class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
    <bean
        class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />


    <bean id="tempService" class="usebeans.TempServiceImpl" />
    <bean id="tempController" class="controller.Temp"/>


    <bean id="urlMapping"
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="index.htm">indexController</prop>
                <prop key="Temp.htm">tempController</prop> <!-- You need to mapp the url to the controller bean-->
            </props>
        </property>
    </bean>

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

    <bean name="indexController"
        class="org.springframework.web.servlet.mvc.ParameterizableViewController"
        p:viewName="index" />

</beans>

使用哪个版本的spring?spring版本是
3.0.2
是否确实要使用
ControllerClassNameHandlerMapping
?您可以删除这个bean并重试一次吗?@Arun,应该删除哪个bean?
bean。然后它抛出一个新的异常
java.lang.IllegalStateException:BindingResult和作为请求属性可用的bean名称“validationForm”的普通目标对象都不表示该命令对象对控制器不可用。(JSP页面没有绑定到
ValidationForm
类)。我完全按照您提到的那样修改了
Temp
控制器类,但不幸的是,它引发了与前面注释中提到的相同的异常。答案可能非常接近。我没有使用jsp。。。所以我认为我不能帮你解决绑定错误问题。。。但是你可以参考这个链接来看看它是如何实现的。如果你能通过带注释的spring mvc来简化spring编程…我们可以使spring配置更好。。。我现在有一些时间限制。。。我将尝试进行这些更改,稍后与您分享。。。
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)
<?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: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">

        <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>    
        <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />


        <bean id="tempService" class="usebeans.TempServiceImpl" />
        <bean name="/Temp.htm" class="controller.Temp" p:tempService-ref="tempService" p:formView="Temp" p:successView="Temp" />


        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="index.htm">indexController</prop>                
                    <prop key="Temp.htm">tempService</prop>                
                </props>
            </property>
        </bean>

        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/jsp/"
              p:suffix=".jsp" />


        //The index controller.

        <bean name="indexController"
              class="org.springframework.web.servlet.mvc.ParameterizableViewController"
              p:viewName="index" />

</beans>
<?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: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">

    <bean
        class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
    <bean
        class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />


    <bean id="tempService" class="usebeans.TempServiceImpl" />
    <bean id="tempController" class="controller.Temp"/>


    <bean id="urlMapping"
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="index.htm">indexController</prop>
                <prop key="Temp.htm">tempController</prop> <!-- You need to mapp the url to the controller bean-->
            </props>
        </property>
    </bean>

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

    <bean name="indexController"
        class="org.springframework.web.servlet.mvc.ParameterizableViewController"
        p:viewName="index" />

</beans>
package controller;

import java.util.HashMap;
import java.util.Map;

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 {
        Map<String, Object> model = new HashMap<String, Object>();
        model.put(getCommandName(), new ValidationForm());
        ModelAndView mv = new ModelAndView("Temp", model);
        return mv;
    }
}