Problem with interaction servlet-jsp
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 retur开发者_运维问答n 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
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.
精彩评论