当我想向现有控制器添加新操作并重新运行项目时,将忽略新操作,但旧操作会起作用。我试图重启Eclipse,重新启动。我要添加的操作:
@RequestMapping(value="dashboard.htm")
public ModelAndView dashboard(HttpServletRequest request, HttpServletResponse response) throws Exception
{
return new ModelAndView("General/dashboard");
}
项目架构:
控制器的完整代码:
@Controller
public class UtilController extends MultiActionController {
@RequestMapping(value="dashboard.htm")
public ModelAndView dashboard(HttpServletRequest request, HttpServletResponse response) throws Exception
{
return new ModelAndView("General/dashboard");
}
@RequestMapping(value="register.htm")
public ModelAndView register(HttpServletRequest request, HttpServletResponse response) throws Exception
{
return new ModelAndView("General/register");
}
@RequestMapping(value="registerValidate.htm")
public ModelAndView registerValidate(HttpServletRequest request, HttpServletResponse response) throws Exception
{
try {
Learner l = new Learner();
l.setEmail(request.getParameter("email"));
l.setForname(request.getParameter("firstname"));
l.setSurname(request.getParameter("lastname"));
//LearnerService.
SendEmail.sendMail("Votre insription sur le site AeroSafety a été effectuée avec succès.", request.getParameter("email"));
} catch (Exception e) {
System.out.println(e.getMessage());
}
return new ModelAndView("General/register");
}
}
我的调度员:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="controller"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/css/**" location="/resources/css/"/>
<mvc:resources mapping="/img/**" location="/resources/img/"/>
<mvc:resources mapping="/js/**" location="/resources/js/"/>
<mvc:resources mapping="/lib/**" location="/resources/lib/"/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven/>
</beans>
我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>PermisMVC</display-name>
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
当我导航到/dashboard.htm时,我收到了这个错误:
2016年7月15日下午11:43:03 org.springframework.web.servlet.PageNotFound noHandlerFound AVERTISSEMENT:在DispatcherServlet中找不到带有URI [/JEEProjetPermis/dashboard.htm]的HTTP请求的映射,名称为“appServlet”
我不知道为什么Eclipse不会在此控制器中获取新操作。
我确定我错过了什么。如果您需要其他信息/文件,请告诉我。