I don't know what I miss, all I want to do is to use spring to catch the redirection and to call the method list, so I can see the message "message" on the listentries.jsp page:
this is my web.xml:
<web-<app>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
This is the context config file, applicationContext, containing the viewresolver :
<beans>
<context:component-scan base-package="net.tirasa.springaddressbook"/>
<bean id="dao" class="net.tirasa.springaddressbook.SpringEntryDAO">
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/Rubrica" />
<property name="username" value="matt3o" />
<property name="password" value="secret" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
this is the AddressBookController class:
@Controller
@RequestMapping(method = GET, value = "/springaddressbook")
public class AddressBookController {
@RequestMapping(value = "/listentries")
public ModelAndView list() {
String message = "hello";
return new ModelAndView("listentries", "message", message);
}
}
and follow the views: index.jsp
<html>
<head><title>Index</title></head>
<body>
<h3>Rubrica:</h3>
<br/>
<a href="listentries.jsp"> List Entries</a><br/>
</body>
and listentries.jsp
<html>
<head><title>List Entries</title></head>
<body>
<h3>List entries</h3>
${message}
</body>
</html>