没有名称为sayHello的请求处理方法

时间:2013-12-20 11:00:33

标签: spring spring-mvc

调度员的servlet

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
etc...
<mvc:annotation-driven/>

<context:component-scan base-package="com.fastek.crm3" />
<mvc:resources mapping="/resources/**" location="/resources/"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="sayHello.html">exampleController</prop>
        </props>
    </property>
</bean>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="exampleController" class="com.fastek.crm3.controller.ExampleController"></bean>

STD10002.jsp -

<body class="bcolor" style="background-color: #EEEEEE;">
    <form:form modelAttribute="stdUser">
        <h3 class="myclass">
            <table>
                <td align="left">Application Users
                    <img src="${pageContext.servletContext.contextPath}/resources/images/Buttons/gray icon/help.png" width="15px" height="15px" id="Help" title="Click here to get help." alt="Help" style="cursor:pointer" onclick="showHelp('CRM100020');">
                    <form:checkbox path="listView" onclick="showHideReport()" id="ListView"></form:checkbox>
                </td>
            </table>
        </h3>
</form:form>

控制器类 -

public class ExampleController extends MultiActionController{
public ModelMap sayHello(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception {
    StdUsers stdUser = new StdUsers();
    System.out.println("/////called from one-----------");
    StdCheckAccessV chk = new StdCheckAccessV();
    chk.setDFlag(1);
    stdUser.setChkAccessV(chk);
    ModelAndView mav = new ModelAndView("CMN/STD100002");
    model.addAttribute("stdUser",mav);
    return model;
}}

的index.jsp -

<body>
    <a href="example/sayHello.html">Say Hello One</a><br>
<body>

StdUSer.java -

public class StdUsers{
 praivate boolean listView;
 getter and setter.....
}

点击index.jsp im getting-404中的链接并发出警告 - 类[com.fastek.crm3.controller.ExampleController]中没有名为'sayHello'的请求处理方法 我是Spring和jstl的新手。

1 个答案:

答案 0 :(得分:1)

MultiActionController的控制器方法不合法。根据Javadoc,返回类型必须是ModelAndViewMapStringvoid

代码(查看3.2.6.RELEASE中的MultiActionController的源代码)在声明的返回类型和上面列出的类型之间进行直接类比较,以确定该方法是否是有效的处理程序方法。 ModelMap根据此不是有效的返回类型。

尝试重构您的方法:

public class ExampleController extends MultiActionController{

    public ModelAndView sayHello(HttpServletRequest request, HttpServletResponse response) throws Exception {
        StdUsers stdUser = new StdUsers();
        System.out.println("/////called from one-----------");
        StdCheckAccessV chk = new StdCheckAccessV();
        chk.setDFlag(1);
        stdUser.setChkAccessV(chk);
        ModelAndView mav = new ModelAndView("CMN/STD100002");
        mav.addAttribute("stdUser", stdUser);
        return mav;
    }
}