Hi Everyone!
Hope all of you are doing well...
I have the following doubt in
Servlet:-
I have 3 servlets ServletA, ServletB and ServletC. I pass a request attribute from ServletC to ServletA using request.setAttribute("url",request.getRequestURL()); . The ServletA has a login form with 2 textboxes username/password and a submit button on clicking the button it takes me to ServletB. On doing request.getAttribute("url") in ServletB i get null.
ServletA
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
System.out.println(request.getAttribute("url"));
pw.println("<html>");
pw.println("<form action=\"ServletB\" method=\"POST\">");
pw.println("<input type=\"text\" name=\"username\">");
pw.println("<input type=\"password\" name=\"password\">");
pw.println("<input type=\"submit\" value=\"Login\">");
pw.println("</form");
pw.println("></html>");
}
ServletB
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
pw.println("<HTML>");
pw.println(request.getAttribute("url"));
pw.println("</HTML>");
}
ServletC
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("url",request.getRequestURL());
request.getRequestDispatcher("/ServletA").forward(request,response);
}
Called using
http://localhost:8080/Servlets/ServletC
The output comes as null in ServletB.
Can anybody explain why this is happening?
Thanks in advance!!