You can do following
- Create a hidden parameter for every jsp named
jspName
and give value for respective JSPs. e.g. for JSP A, parameter name isjspName
and value isa
, for JSP B, parameter name isjspName
and value isb
Read this hidden parameter in the servlet using following code.
String jspName = request.getParameter("jspName"); RequestDispatcher rd = request.getRequestDispatcher(jspName); rd.forward(request, response);
When you are calling the servlet from JSP A, then it will have paramter japName=a
, when servlet code is running, it will retrieve the value a
from request.getParamter("jspName")
and a getRequestDispatcher(jspName)
will create the dispatcher for the same and rd.forward(request, response)
will forward to the jsp.