Write your Servlet class like this
public class ServletToJSP extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//communicating a simple String message.
String message = "Example source code of Servlet to JSP communication.";
request.setAttribute("message", message);
//Servlet JSP communication
RequestDispatcher reqDispatcher = getServletConfig().getServletContext().getRequestDispatcher("jsp url");
reqDispatcher.forward(request,response);
}
}
jsp page
<%
String message = (String) request.getAttribute("message");
out.println("Servlet communicated message to JSP "+ message);
%>