In this session you will learn:
Understand Request Dispatcher
JSP
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
10. Page 12Classification: Restricted
public void doGet(HttpServletRequest req,
HttpServletResponse res)
{
if( valid)
{
RequestDispatcher rd =
req.getRequestDispatcher(“Home.jsp”)
rd.forward(req, res);
}
else
{
req.setAttribute(“error”, “username or password
is invalid”);
RequestDispatcher rd
=req.getRequestDispatcher(“Login.jsp”);
rd.forward(req, res);
}
}
Home About
username/pwd
invalid
login
11. Page 13Classification: Restricted
public void doGet(HttpServletRequest req,
HttpServletResponse res)
{
if( valid)
{
RequestDispatcher rd =
req.getRequestDispatcher(“Home.jsp”)
rd.forward(req, res);
}
else
{
req.setAttribute(“error”, “username or password is
invalid”);
RequestDispatcher rd
=req.getRequestDispatcher(“Login.jsp”);
rd.forward(req, res);
}
}
Home About
L
Login.jsp
username/pwd
invalid
${requestScope.e
rror}
login
error=“username/pwd is
invalid
12. Page 14Classification: Restricted
JSP
• Java Server Pages
• used for developing server side response
• to add dynamic functionality to web page
• java code is written inside html
• gets the container support
• Life Cycle methods
• jspInit()
• _jspService
• jspDestroy
13. Page 15Classification: Restricted
Compilation & Execution
• Execution of jsp is done in two phases
• translation
• Web container translates Hello.jsp to _Hello.java
• Converts jsp to servlet
• compilation
• generates Hello.class file
• load the class file
• creates the instance of Hello
• calls init method
• call service method
• calls destroy method.