JSP FAQs

What is a JSP ?

JavaServer Pages (JSP) is a technology that helps software developers create dynamically generated web pages based onHTML, XML, or other document types.
Basically it is html file with JAVA logic inside it with the extension of .jsp

.jsp  files (html + java code) = .php (html + php code) = .xhtml in .net (html + C# code or razor syntax)

How JAVA logic is inserted inside html markup?
<%@ page global attributes and imports %>
<%@ include file="jsp file location" %>
<%! Java functions to be exectued %>
<% Java code %>
<%=JAVA expression %>

How .jsp s are interpreted in a server ?

abc.jsp will be executed as a servelt named abc_jsp. So corresponding abc_jsp.class and abc_jsp.java file will be generated in a server folder to be executed.

Depending on the request (GET or POSt...) the following will be parsed within doGET() or doPOST() ...
  • All the html content will be rendered in printwriter.println("html content") statements.
  • All the Java codes will be executed as normal java  code.
  • Any Java functions decalred in <%! %> will be parsed outside doGET() or doPOST() 
Then the final HTML data will be sent to browser/client.

What are implicit objects in JSP page ?
Meaning you dont have to create references to some objects. In a jsp scope they are created for you.
request.attribute --> HttpServeletRequest objects
session.attribute --> HttpSession objects
application.attribute --> ServletContext objects

What is the role of PageContext class ?


This object is intended as a means to access information about the page while avoiding most of the implementation details.

This object stores references to the request and response objects for each request. The application, config, session, and out objects are derived by accessing attributes of this object.
  1. JSP Page – Scope: PAGE_CONTEXT
  2. HTTP Request – Scope: REQUEST_CONTEXT
  3. HTTP Session – Scope: SESSION_CONTEXT
  4. Application Level – Scope: APPLICATION_CONTEXT
for example,
without 
request.setAttribute("key","value");
session.setAttribute("key", "value"),
you can 
pageContext.setAttribute("key", "value", PageContext.SESSION_SCOPE);
pageContext.setAttribute("key", "value", PageContext.REQUEST_SCOPE);
Share:

0 comments: