1

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>
MdC
  • 107
  • 1
  • 4
  • 16
  • 1
    What is the issue you are facing ? what URL you are trying to hit ? Is application getting published fine ? – Amit.rk3 Jul 31 '15 at 10:10
  • the link is static, so I can see the index page through tomcat, and I get redirected to listentries.jsp. anyway I don't see the message – MdC Jul 31 '15 at 10:17

1 Answers1

0

EL was introduced in Servlet version 2.4. Append this code at the top of your web.xml to get the EL variable value,

<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

Anand
  • 305
  • 1
  • 2
  • 9
  • I have this : – MdC Jul 31 '15 at 11:22
  • your web.xml seems to be fine. Try including `<%@ page isELIgnored="false" %>` in your jsp file. – Anand Jul 31 '15 at 11:31
  • Also please take a look at [this](http://stackoverflow.com/questions/472500/javascript-string-replace-str-works-weirdly-in-jsp-file/472573#472573) link. – Anand Jul 31 '15 at 11:37