0
映射
我web.xml
內容是:Spring MVC的警告:未找到HTTP請求與URI
<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
方法時引起異常。任何幫助?
你戰爭的名字是springEmployeeAnotations? – Subin
和你的url就像localhost:8080/springEmployeeAnotations/viewEmployee? – Subin
url是'http:// localhost:8080/springEmployeeAnotations/viewEmployee.htm' – nebula