0

私のweb.xmlコンテンツは次のとおりです。

<servlet>
        <servlet-name>springDispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springDispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern> <!-- Why not put / instead of *.html? -->
    </servlet-mapping>


    <!-- ContextLoader -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/conf/applicationContext.xml
            /WEB-INF/conf/applicationContext-data.xml
            /WEB-INF/conf/applicationContext-service.xml

        </param-value>
    </context-param>

applicationContext.xmlは:

<!-- Default ViewResolver -->
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
<bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

<context:annotation-config />

<context:component-scan base-package="com.lftechnology.controller" />

<!-- <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" 
    /> -->

<bean
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

<bean class="com.lftechnology.controller.EmployeeController">
    <property name="employeeService" ref="employeeService" />
    <property name="departmentService" ref="departmentService"></property>
</bean>

最後に、コントローラーは次のとおりです。

@Controller
public class EmployeeController {

    EmployeeService employeeService;
    DepartmentService departmentService;

    //getters setters    

    @RequestMapping("/deleteEmployee.htm")
    public String deleteEmployee(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        //
        return "redirect:viewEmployee";
    }

    @RequestMapping("/viewEmployee.htm")
    public ModelAndView viewEmployee(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        Map<String, Object> model = new HashMap<String, Object>();
        //
        return new ModelAndView("viewEmployee", "model", model);
    }

}

例外:

 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/springEmployeeAnotations/viewEmployee.htm] in DispatcherServlet with name 'springDispatcher' 

このコードの何が問題なのかわかりません。少なくとも私にはすべてが正しいように思えます。viewEmployeeコントローラーのメソッドに入ろうとすると、例外が発生します。ヘルプはありますか?

4

2 に答える 2

0

これを試して:

<servlet-mapping>
<servlet-name>springDispatcher</servlet-name>
<url-pattern>/WEB-INF/jsp/*.htm </url-pattern>
</servlet-mapping>
于 2012-12-11T17:56:58.420 に答える
-2

コントローラー クラスを着信要求にマップしましたか?

@RequestMapping("/springEmployeeAnnotations") を使用してそれを行います

@Controller
@RequestMapping("/springEmployeeAnotations")
public class EmployeeController { .....

Tp

于 2012-12-11T18:28:54.653 に答える