Example: JSP calling Servlet

<html>

<body>
Forwarding to servlet

<%
//Servlet deployed in same Container running this
//JSP file

String otherServletPath = "/Hello";


//application in JSP refers to ServletContext instance you get
//when in a servlet invoking
// getServletConfig().getServletContext()

RequestDispatcher mydisp = application.getRequestDispatcher(otherServletPath);

//Now you can add any elements you want to
//the current request (req) object and invoke the
//servlet

mydisp.forward(request,response);



%>


</body>
</html>

© Lynne Grewe