我的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
控制器的方法时导致异常。有帮助吗?