Please enable JavaScript.
Coggle requires JavaScript to display documents.
JSP (JSP Predefined Variables (Session (Represent the HttpSession object…
JSP
JSP Predefined Variables
Session
- Represent the HttpSession object associated with the request, obtained from request.gerSession().
Application
- Represent the ServletContext object for storing persistent data for all clients.
- The difference between session and application is the session is tied to one client but application is for all clients to share persistent data.
Out
- Represent the character output stream, which is an instance of PrintWriter obtained from response.getWriter().
- You can use it to send character content to the client.
Config
- Represents the ServletConfig object for the page.
Response
- Represent the servler's response, which is an instance of HttpServletResponse.
- You can use it to set response type and send output to the client.
Pagecontext
- Represents the PageContext object.
- PageContext is a new class introduced in JSP to give a central point of access to many page attributes.
Request
- Represent the client's request, which is an instance of HttpServletRequest.
- You can use it to access request parameters, HTTP headers such as cookies, hostname
Page
- Page is an alternative to this.
What is JSP?
Mostly HTML page , with extension .jsp
Is a Java standard technology that enables you to write dynamic, data-driven pages for your Java web applications
-
Compiled at request time (first request, a little slow)
-
-
JSP Technology
- Provide a simplified, fast way to create web pages that display dynamically generated content.
- JSP is a standard extension of Java and defined on top of Servlet extensions.
- Goal- to simplify management and creation of dynamic web pages.
- It is platform-independen, secure and makes use of Java s a server side script language.
-
-
JSP Lifecycle Method
-
-
jspInt()
The container calls this to initialize servlet instance. It is called only once for servlet instance and preceded every other method.
JSP Constructors
Expression
-
<%= Java-expression %> Example:
- <%=“Fred”+ “ + Flintstone %> - prints "Fred Flintstone" to the browser
- <%=Math.sqrt(100)%> - prints 10 to the browser
The expression is evaluated, converted into a string and sent to the output stream of the servlet.
Scriptlet
<% Java statement %> Example:
Enables to insert a Java statement into servlet's jspService method which invoked by the service method.
Declaration
-
<%! Java method or field declaration %>
Example:
<%!
Public void jspDestroy() {
System.out.println(“JSP Destroyed”);
}
Public void jspInit() {
System.out.println(“JSP Loaded”);
}
int myVar = 123;
%>
-
JSP Directives
Include
- Lets you insert a file to the servlet when the page is translated to a servlet.
- The include directive must be placed where you want to file to be inserted.
Taglib
- taglib lets you define custom tags.
Page
- Lets you provide information for the page, such as importing classes and setting up content type.
- The page directive can appear anywhere in the JSP file.
JSP Page
Has the extension .jsp, this signals to the web server that JSP engine will process elements on this page.
Is a page created by the web developer that includes JSP technology-specific tags, declarations and possibly scriptlets in combination with other static HTML or XML tags.
JSP Comment
-
If you don’t want the comment appear in resultant HTML file, use the following comment in JSP:
<% -- JSP Comment -- %>