Let me see if I understand: you want to call the JSP from the servlet and make some variables (which are under the control of the servlet) available to the JSP. Right?
Then forget about the PageContext , it is just specific to JSP pages and cannot be accessed from the servlet. Any attribute specified in the context of a request, session, or servlet will be available in the JSP. PageContext is a region wider than the previous one, and it has a findAttribute method findAttribute , when called, will look for an attribute with the given name inside the context context of the page, request, session, or servlet (in that order).
So, you only need to set these variables as attributes in one of these areas, I would suggest using request one ( HttpServletRequest.setAttribute("foo", "fooValue") ) and then use it in your JSP using a value expression ( ${foo} ).
source share