0

I work this jsp, servlet and struts. (Jsp version 2.0, servlet 2.4, struts 1). There is one "for" loop in another one.

...
<%
    String[] profileNames = { "Page", "Report", "XML API" };
    for (String profileName : profileNames) {

        LRUCache profile = ObjectStore.getStore(profileName + " Profile");
        pageContext.setAttribute("profile", profile);
        pageContext.setAttribute("profileName", profileName);
%>

<table class="sortable" id="<%=profileName%>">
    <tr class=title>
        <th class=contentTable>description</th>
        <th class=contentTable>qty</th>
    </tr>
    <c:forEach var="profile" items="${profileItems}">
        <tr>
            <td>${profile.object.description}</td>
            <td>${profile.object.qty}</td>
        </tr>
    </c:forEach>
</table>
<%
    }
%>

I need this jsp page without java code. How to implement it?

Thank you for any help!

Dan
  • 393
  • 1
  • 4
  • 19

1 Answers1

2

Send the same attributes that you are currently "putting" in pageContext: profile and profileName on the Servlet (or any other similar technology you are using for handling requests/responses).

Something like: request.setAttribute("key", value); on the Servlet class.

UPDATE: I did a quick search over here and you may really want to take a look a this one.

Community
  • 1
  • 1
x80486
  • 6,627
  • 5
  • 52
  • 111
  • Thank you for your help! Can I call java methods with parameters in jsp page (version 2.0) like this: `ObjectStore.getStore(profileName + " Profile");` ? – Dan Mar 25 '15 at 07:45
  • Definitely, With the right `<%@ page import="path.to.YourClass" %>` (in your case `ObjectStore`) directive declared first, you can do that, but I strongly recommend you to only _use_ data in your JSPs, it's easier to maintain in the long run, although I also know sometimes requirements and/or time are kind of crazy. Basically, you do the stuff that you have to do, for instance in a `Servlet`, and then send the data and render the stuff. This [link](http://www.javatpoint.com/jsp-tutorial) is really useful. Have a great day! – x80486 Mar 25 '15 at 12:18