0

I'm trying to send a parameter from a servlet to a jsp file. This is the servlet:

public class HomepageController extends HttpServlet {

private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        CategoryService cs = new CategoryService();

        request.setAttribute("attribute", "Hello world!");
        request.getRequestDispatcher("/views/homepage.jsp").forward(request,response);
    }
}

and in the jsp I try to access it like this ${attribute} but it doesn't work. It shows as if it is not defined.

Jones
  • 1,036
  • 5
  • 20
  • 37

1 Answers1

0

Solved it by adding the version to the web.xml file.

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Archetype Created Web Application</display-name>

<servlet>
    <servlet-name>HomepageController</servlet-name>
    <servlet-class>controller.HomepageController</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>HomepageController</servlet-name>
    <url-pattern>/homepage</url-pattern>
</servlet-mapping>

Jones
  • 1,036
  • 5
  • 20
  • 37