Example of Jsp Scriptlet Tag -
<html>
<body>
<%! int data = 50; %>
<%="Value of the variable is:"=data %>
</body>
</html>
Example of Declaration Tag -
<html>
<body>
<%! int cube(int n){ return n*n*n;} %>
<%="Cube of 3 is:"=cube(3) %>
</body>
</html>
# JSP Implicit Objects
----------------------
There Are 9 JSP implicit objects. These objects are created by the web container that are available to all
the jsp pages.
The available implict objects are out , request , config , session , application etc.
1. OUT - jspWriter
2. Request - HttpServletRequest
3. Response - HttpServletResponse
4. Config - ServletConfig
5. application - ServletContext
6. Session - HttpSession
7. pageContext - pageContext
8. page - Object
9. Exception - Throwable
# JSP Request implicit object
-----------------------------
The JSP Request ia an implicit object of type HttpServletRequest i.e. created for each jsp request by the
web container. It can be used to get request information such as parameter, header information , remote
address, server name, server port, content type , character encoding etc.
Example of JSP request implicit object
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go">
</form>
welcome.jsp
-----------
<%
String name=request.getParameter("uname");
out.print("welcome"+name);
%>
# JSP Response implicit object
------------------------------
In JSP , Response is an implicit object of type HttpServletResponse . The instance of HttpServletResponse is
created by the web container for each JSP request.
Example of JSP response implicit object
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go">
</form>
welcome.jsp
-----------
<%
response.sendRedirect("https://www.serverxperts.com");
%>
# Session implicit object
-------------------------
In JSP , session is an implicit object of type HttpSession. The Java developer can use this object to set,
get or remove attribute or to get session information.
Example of Seeeion implicit object
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go">
</form>
welcome.jsp
-----------
<%
String name=request.getParameter("uname");
out.print("welcome"+name);
session.setAttribute("user",name);
<a href="second.jsp">Second jsp Page</a>
%>
Second.jsp
<%
session.setAttribute("user");
out.print("Hello"+name);
%>
# JSP application implicit object
---------------------------------
In JSP , application is an implicit object of type ServletContext. The instance of ServerContext is created
only once by the web container when application or project is deployed on the server.
Example of Application implicit object
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go">
</form>
web.xml file
<web-app>
<servlet>
<servlet-name>Rohan Kumar</servlet-name>
<jsp-file>/welcome.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Rohan Kumar</servlet-name>
<ur!-pattern>/welcome</ur!-pattern>
</servlet-mapping>
<context-paran>
<param-name>dname</param-name>
<param-value>sun.jdbc.odbc.jdbcodbcDriver</param-value>
</context-param>
</web-app>
welcom.jsp
<%
out.print(welcome"+request.getParameter("uname"));
String driver=application.getInitParameter("dname");
out.print("driver name is="+driver);
%>