Scriptlet Element
- One or more statements that are executed each time the page is requested.
- you can also insert variable and method declarations, Java expressions, and so on in scriptlet.
Syntax:-
<% Java Code or statement %>
Example:-
Totam sum:-<% 12+12 %>output:-
24
Implicit Objects
- In Servlet you learned,how to use such objects as HttpServletRequest, HttpServletResponse, HttpSession, and ServletContext.
- JSPs follow same rules as servlets,they also need to be able to get access to these objects.
- JSPs have a number of predefined variables that give you access to these objects.
1)request:-
This variable use to access the HttpServletRequest object.Example:-
<% String name=request.getParamter("name"); %>
2)response:-
This variable use to access the HttpServletReponse object.Example:-
<% response.setContentType("text/html"); %>
3)out:-
This variable use to access the JspWriter class which has same as PrintWriter in Servlet.Example:-
<% out.println("This is implicit Object"); %>
4)session:-
This variable provide the instance of the HTTPSession object.5)exception:-
This variable provide an instance of Throwable object and shows error information which is only available from the JSP error page that contains the directive isErrorPage=true.6)page:-
This variable provide the instance of the JSP's Java class which processes the current request.7)pageContext:-
This variable presents the javax.servlet.jsp.PageContext class,which have methods for communicate with scoped data.8)application:-
This variable provides you access to the ServletContext object without calling getServletConfig().getContext().9)config:-
This variable provides access servletConfig()object and give configuration information about JSP.Actions
JSP actions provide runtime instructions to the JSP Containers e.g- a JSP
action can include a file, forward a request to another page or create an instance of
a JavaBean.
A JavaBean is a Java class that has following signature accessing the bean's properties.
->no-arguments constructor.
->private or protected fields (properties)
->public setter/getter methods .
jsp:include:-
jsp:include action adds the content of the included page at the runtime.<jsp:include page="login.jsp" />
jsp:forward:-
forward action enables you to redirect the program flow to a different HTML file, JSP or servlet while maintaining the same request and response objects. This directive works as the forward() method of the RequestDispatcher.<jsp:forward page="welcome.jsp" />
Java Beans:-
JavaBeans are used for data exchange, and help to separate business logic from presentation.A JavaBean is a Java class that has following signature accessing the bean's properties.
->no-arguments constructor.
->private or protected fields (properties)
->public setter/getter methods .
Properties of JavaBean:-
1)jsp:useBean:-
Creates or re-uses a JavaBean available to the JSP page. Attributes supported are Id/ Class/Scope/Type/beanName.<:useBean id="User" class="com.web.JSPExam" />
2)jsp:getProperty:-
Gets a property from the specified JavaBean.3) jsp:setProperty:-
Sets a property in the specified JavaBean. Attributes supported are name/ property / param /value.<jsp:useBean id="Student" class="com.web.FirstJsp" />
<jsp:setProperty name="Student" property="LastName" value="Dwivedi" />
<jsp:setProperty name="Student" property="FirstName" value="Shivank" />


