Passing data from servlet to another servlet using RequestDispatcher

前端 未结 2 502
说谎
说谎 2021-01-05 18:05

I am trying to pass data from one servlet to another using the RequestDispatcher. This is my code for the Dispatcher.

String address;

address = \"/Java Reso         


        
2条回答
  •  臣服心动
    2021-01-05 18:36

    You just need to pass servlet-mapping 's url-pattern in the getRequestDispatcher.

    Let say your servlet mapping is "myMap" for the "MapOut" Servlet in the web.xml.Then it should be

    RequestDispatcher dispatcher = request.getRequestDispatcher("/myMap");
    dispatcher.forward(request,response);
    

    doGet() of forwarded Servlet will be called.

    Example: web.xml

          
            
            MapOut
            coreservlets.MapOut
          
          
            MapOut
            /myMap 
          
    

提交回复
热议问题