0

I have a implementation prolbem.

I have create a jsp and a servlet file. I have a remoteInterface of session bean. I want to use remoteInterface in servlet and after write the data on the jsp.

The client must see only the result page.

For Example:

A method of session bean return a Collection. I use this collection in the servlet and after this stamp all the element in the jsp.

Can you help me with a code example.

Thanks

skaffman
  • 398,947
  • 96
  • 818
  • 769
zp26
  • 1,507
  • 8
  • 20
  • 38

1 Answers1

0

Implement doGet() method as follows (using Product as example of real world entity):

List<Product> products = yourRemoteInterface.list();
request.setAttribute("products", products); // Will be available as ${products}
request.getRequestDispatcher("/WEB-INF/products.jsp").forward(request, response);

Implement the JSP as follows:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<table>
    <c:forEach items="${products}" var="product">
        <tr>
            <td>${product.name}</td>
            <td>${product.description}</td>
            <td>${product.price}</td>
            <td><img src="${product.image}" /></td>
        </tr>
    </c:forEach>
</table>

Map the servlet in web.xml on an url-pattern of for example /products, then you'll be able to run the servlet and show the JSP by http://example.com/contextname/products.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555