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

1 Answer 1

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.

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

Comments

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.