Search code examples
javajspspring-mvcservlets

call servlet from controller with parameters to servlet


I am writing a jsp file to call a controller with some parameters. And from this controller i want to call a servlet by passing the values from the controller. And with in the servlet i should get access to the parameters. Is it possible to forward values from jsp to servlet via controller?


Solution

  • Yes it's possible in Spring controller,

    Try this in Spring controller:

    public void requestedURL(HttpServletRequest req, HttpServletResponse res){
    String jspParameter = request.getParameter("param_name");
    req.getRequestDispatcher("your servlet url pattern?param1="+jspParameter).forward(req, res);
    }