0

i know i am asking a bit silly question., but please guys help me and let me know. Scanario: I have 2 servlets and 1 html file. 1st servlet is redireted to html file which on submit redirects to 2nd servlet. I need a attribute value from 1st servlet. I know., if we can use RequestDispatcher between two servlets., but here situattion is different

Please anyone let me know how can i get attribute value from first servlet to second servlet

Note: In First servlet., through anchor tag, HTML page is referred

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Chandra Kishore
  • 47
  • 1
  • 2
  • 11
  • Another related question on the subject: http://stackoverflow.com/questions/4253660/passing-object-from-jsp-to-servlet/ – BalusC Sep 10 '15 at 15:10

1 Answers1

0

You can use HttpSession for it. For example,

public class Servlet1 extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        req.getSession().setAttribute("attribute", "value");
        // do stuff...
    }

}

public class Servlet2 extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        String value = (String) req.getSession().getAttribute("attribute");
        req.getSession().removeAttribute("attribute");
        // do stuff...
    }

}
emamedov
  • 96
  • 1
  • 2