1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Calling a JSP with different parameters

Discussion in 'JSP' started by macaroni, May 14, 2012.

  1. macaroni

    macaroni New Member

    Joined:
    May 14, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello people,
    i would like to know how to call a JSP-file with different parameters so that I can use it as a blueprint for several webpages in my project.

    My project is quite simple and only for learning purposes:
    I have a start page with several cooking recipes. If I click on one of those recipes I will get a detailed view of the recipe, which includes some text and an image.
    However, I don't want to create a new jsp-file for every recipe, because all recipes have the same layout. Instead, I want to use one and the same jsp-file for an arbitrary amount of recipes. The content of those recipes should be located in one or several XML-files.

    I couldn't find a good example on the internet, so I would be very happy if someone could help me here.
     
  2. meenal deshpande

    meenal deshpande New Member

    Joined:
    Oct 11, 2018
    Messages:
    20
    Likes Received:
    2
    Trophy Points:
    3
    Gender:
    Female
    You can only invoke methods with arguments in EL if you're targeting and running a Servlet 3.0 compatible container (e.g. Tomcat 7, Glassfish 3, JBoss AS 6, etc) with a web.xml declared conform Servlet 3.0. This servlet version comes along with EL 2.2 which allows invoking arbitrary instance methods with arguments.

    Assuming that you've a ${bean} in the scope which refers to an instance of a class which has a method something like public Object[] getArray(String key), then you should be able to do this:

    <c:forEach items="${bean.getArray('foo')}" var="item">
    ${item} <br />
    </c:forEach>
    or even with another variable as argument

    <c:forEach items="${bean.getArray(foo)}" var="item">
    ${item} <br />
    </c:forEach>
     

Share This Page