Servlet-jsp interaction issue

I have a implementation of a space.

I created a jsp file and a servlet. I have a remoteInterface session bean. I want to use remoteInterface in the servlet and after writing data to jsp.

The client should see only the results page.

Example:

The bean session method returns a collection. I use this collection in the servlet, and after that mark all the elements in jsp.

Can you help me with some sample code.

thank

0
source share
1 answer

Implement the method doGet()as follows (using Productas an example a real-world object):

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

Deploy 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>

web.xml url-pattern, , /products, JSP http://example.com/contextname/products.

0

Source: https://habr.com/ru/post/1784136/


All Articles