JavaServer Pages (JSP) is a technology for developing web pages that support dynamic content which helps developers insert java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %>.
What are the advantages of JSP over Servlet?
What are the scopes available in <jsp:useBean>?
What are scripting elements?
What is a scriptlet?
What are JSP declarations?
What is a JSP expression?
What are implicit objects in JSP?
JSP offer several advantages as listed below:
- Performance is significantly better because JSP allows embedding Dynamic Elements in HTML Pages itself.
- JSP are always compiled before it's processed by the server unlike CGI/Perl which requires the server to load an interpreter and the target script each time the page is requested.
- JavaServer Pages are built on top of the Java Servlets API, so like Servlets, JSP also has access to all the powerful Enterprise Java APIs, including JDBC, JNDI, EJB, JAXP etc.
- JSP pages can be used in combination with servlets that handle the business logic, the model supported by Java servlet template engines.
What are the advantages of JSP over Servlet?
JSP is a serverside technology to make content generation a simple appear.The advantage of JSP is that they are document-centric. Servlets, on the other hand, look and act like programs. A Java Server Page can contain Java program fragments that instantiate and execute Java classes, but these occur inside an HTML template file and are primarily used to generate dynamic content. Some of the JSP functionality can be achieved on the client, using JavaScript. The power of JSP is that it is server-based and provides a framework for Web application development.
Include Directive
|
Include Action
|
include directive is processed at the translation time
|
Include action is processed at the run time.
|
include directive can use relative or absolute path
|
Include action always use relative path
|
Include directive can only include contents of resource it will not process the dynamic resource
|
Include action process the dynamic resource and result will be added to calling JSP
|
We can not pass any other parameter
|
Here we can pass other parameter also using JSP:param
|
We cannot pass any request or response object to calling jsp to included file or JSP or vice versa
|
In this case it’s possible.
|
What are the scopes available in <jsp:useBean>?
The scopes available in <jsp:useBean> are as follows:
- page scope:: It specifies that the object will be available for the entire JSP page but not outside the page.
- request scope: It specifies that the object will be associated with a particular request and exist as long as the request exists.
- application scope: It specifies that the object will be available throughout the entire Web application but not outside the application.
- session scope: It specifies that the object will be available throughout the session with a particular client.
What are scripting elements?
JSP scripting elements let you insert Java code into the servlet that will be generated from the current JSP page. There are three forms:
- Expressions of the form
<%= expression %>
that are evaluated and inserted into the output, - Scriptlets of the form
<% code %>
that are inserted into the servlet's service method, - Declarations of the form
<%! code %>
that are inserted into the body of the servlet class, outside of any existing methods.
What is a scriptlet?
A scriptlet contains Java code that is executed every time a JSP is invoked. When a JSP is translated to a servlet, the scriptlet code goes into the
service()
method. Hence, methods and variables written in scriptlets are local to the service()
method. A scriptlet is written between the <% and %> tags and is executed by the container at request processing time.
As the name implies, JSP declarations are used to declare class variables and methods in a JSP page. They are initialized when the class is initialized. Anything defined in a declaration is available for the whole JSP page. A declaration block is enclosed between the <%! and %> tags. A declaration is not included in the
service()
method when a JSP is translated to a servlet.
A JSP expression is used to write an output without using the
out.print statement
. It can be said as a shorthand representation for scriptlets. An expression is written between the <%= and %> tags. It is not required to end the expression with a semicolon, as it implicitly adds a semicolon to all the expressions within the expression tags.What are implicit objects in JSP?
Implicit objects in JSP are the Java objects that the JSP Container makes available to developers in each page. These objects need not be declared or instantiated by the JSP author. They are automatically instantiated by the container and are accessed using standard variables; hence, they are called implicit objects.The implicit objects available in JSP are as follows:
- request
- response
- pageContext
- session
- application
- out
- config
- page
- exception
The implicit objects are parsed by the container and inserted into the generated servlet code. They are available only within the jspService method and not in any declaration.
No comments:
Post a Comment