ServletChaining
// FirstServlet
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet {
String name ;
ServletConfig config;
public void doGet(HttpServletRequest request ,
HttpServletResponse response)
throws ServletException , IOException {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
name = request.getParameter("name");
RequestDispatcher rd = config.
getServletContext().getRequestDispatcher("SecondServlet");
if(name!=null) {
request.setAttribute("UserName",name);
rd.forward(request , response);
// Forward the value to another Secondservlet
} else {
response.sendError(response.SC_BAD_REQUEST,
"UserName Required");
}
}
}
Comments
Post a Comment