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!

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your help! Can I call java methods with parameters in jsp page (version 2.0) like this: ObjectStore.getStore(profileName + " Profile"); ?
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 is really useful. Have a great day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.