If you want to send data from the servlet to the view, you can use forward from the servlet to your JSP and add all the information you need to show as attributes of the request, then in the JSP you can access these attributes without problems.
Here is an example:
@WebServlet("busqueda.jsp")
public class BusquedaServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//realizas la búsqueda aquí...
List<Resultado> resultados = ... //lista con los resultados de la búsqueda
//colocamos los resultados de la búsqueda como atributo del request
request.setAttribute("resultados", resultados);
//realizamos un forward a la página JSP donde mostraremos los resultados
request.getRequestDispatcher("busqueda.jsp").forward(request, response);
}
}
JSP, the file searched.jsp (I use JSTL, recommended to avoid using scriptlets in your JSP code):
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Resultado de búsqueda</title>
</head>
<body>
<table>
<tr>
<th>Id</th>
<th>Descripción</th>
</tr>
<c:forEach items="${resultados}" var="resultado">
<tr>
<td>${resultado.id}</td>
<td>${resultado.descripcion}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
It is assumed that the class Resultado
has the following structure:
public class Resultado {
private int id;
private String descripcion;
//getters y setters para los campos de arriba
}