jeudi 16 juin 2016

Spring MVC : new action ignored

I don't know much Spring MVC,

but when I want to add a new action to an existing controller, and re-run the project, the new action is ignored, but old actions work. I tried to restart Eclipse, reboot.

The action I want to add :

@RequestMapping(value="dashboard.htm")
public ModelAndView dashboard(HttpServletRequest request, HttpServletResponse response) throws Exception
{
	return new ModelAndView("General/dashboard");
}

Architecture of the project :

enter image description here

Full code of the controller :

@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");
	}
}

My dispatcher :

<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>

My 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>

When I navigate to /dashboard.htm, I got this error :

juin 15, 2016 11:43:03 PM org.springframework.web.servlet.PageNotFound noHandlerFound
AVERTISSEMENT: No mapping found for HTTP request with URI [/JEEProjetPermis/dashboard.htm] in DispatcherServlet with name 'appServlet'

I don't know why Eclipse doesn't fetch the new actions in this controller.

I'm sure I'm missing something. Let me know if you need another info / file.

Aucun commentaire:

Enregistrer un commentaire