- These objects will be generated automatically in jsp equivalent servlet. So these objects are called Implicit Objects.
1. request -> javax.servlet.http.HttpServletRequest -- request scope
2. response -> javax.servlet.http.HttpServletResponse -- response scope
3. out -> javax.servlet.jsp.JspWriter -- page scope
4. session -> javax.servlet.http.HttpSession -- session scope
5. page -> this(current invoking object ref)-- page scope
6. pageContext -> javax.servlet.jsp.PageContext -- page scope
7. application -> javax.servlet.ServletContext -- web application scope
8. config -> javax.servlet.ServletConfig -- page scope
9. exception -> java.lang.Throwable -- page scope
- Page Scope:- means object is visible only in the current jsp page.
- Session Scope:- means object is visible across the multiple request.
- Web application Scope:- means object is visible in all the web resources of webapplication
- request Scope:- means in all the web resources who participates in request cycle.
Question;- what is the difference between page, pageContext implicit objects?
A:- pageimplicit object is nothing but this keyword. So it holds reference of the current jsp equivalent servlet object. the type of page object is java.lang.Object.
pageContext object is created having multiple details about current jsp page like request object, response object, buffer size and etc., details Using this objects only lot of other implicit objects will be created.
- The type of pageContext object is javax.Servlet.jsp.PageContext(class)
Commenting code in jsps:-
- A jsp page can have 3 types of comments
1. Java Comments / scripting comments
(// (or) /* java code */)
2. Hidden comments / Jsp comments
(<%-- jsptags --%>
3. Html comments
(<!-- Htmlcode -->
- page compiler recognizes jsp comments.
- Java compiler (javac) recognizes scripting comments(java comments)
Note:- Java code placed in jsp is technically called as script.
- Html Interpreter available in browser software recognizes Html comments.
visibility
1. In source code jsp equivalent servlet
YES
NO
YES
2. In compiled code of jsp equivalent servlet
NO
NO
YES
3. Html code that goes to browser
NO
NO
YES
4. Output
NOT VISIBLE
NOT VISIBLE
NOT VISIBLE
- For Html to jsp communication take file/url-pattern of jsp use either in action attribute of form tag or href attribute of <a>
- For Jsp to database communication place jdbc code in the jsp using scriptlets.
- we can import packages in jsp as shown below.
<%@ page import="java.sql.*"%>
- when webresource of webapplication uses third party make sure that you are adding API related jar files in the class path of MyComputer Environment
variable and WEB-INF lib folder of web application.
3.1 Page Directive Tag
- This tag is very useful to provide global information to Jsp page.
- when multiple threads acts on single object conquerently or simultaneously it is recommended to make object as thread safe
object by using synchronization concept.
- Servlet class object is not thread safe by default because multiple requests given to a servlet
will act as multiple threads on the object conqurently or simultaneously. So to make servlet as threadsafe Servlet. Implement
javax.servlet.SingleThreadModel interface. So the underlaying web, application server automatically takes care of making
servlet as thread safe servlet.
Standard Syntax:-
<%@ page attribute%>
Xml Syntax:-
<jsp:directive page attribute/>
Subscribe to:
Comments (Atom)