<-Pre | Home | Next-> |
What is Java Server Pages technology?
JavaServer Pages (JSP) technology offers a simple way to create dynamic web pages that are both platform-independent and server-independent, giving you more freedom through Java technology's "Write Once, Run Anywhere" capability.
What is a JSP Page?
A JSP page is a text document that contains two types of text: static data, which can be expressed in any text-based format (such as HTML,WML,XML,etc), and JSP elements, which construct dynamic content.JSP is a technology that lets you mix static content with dynamically-generated content.
Why do I need JSP technology if I already have servlets?
JSP pages are compiled into servlets, so theoretically you could write servlets to support your web-based applications. However, JSP technology was designed to simplify the process of creating pages by separating web presentation from web content. In many applications, the response sent to the client is a combination of template data and dynamically-generated data. In this situation, it is much easier to work with JSP pages than to do everything with servlets.
How is a JSP page invoked and compiled?
Pages built using JSP technology are typically implemented using a translation phase that is performed once, the first time the page is called. The page is compiled into a Java Servlet class and remains in server memory, so subsequent calls to the page have very fast response times.
Does JSP technology require the use of other Java platform APIs?
JSP pages are typically compiled into Java platform servlet classes. As a result, JSP pages require a Java virtual machine that supports the Java platform servlet specification.
What are the advantages of JSP?
> JSP pages easily combine static templates, including HTML or XML fragments, with code that generates dynamic content.
>JSP pages are compiled dynamically into servlets when requested, so page authors can easily make updates to presentation code. JSP pages can also be precompiled if desired.
>JSP tags for invoking JavaBeans components manage these components completely, shielding the page author from the complexity of application logic.
>Developers can offer customized JSP tag libraries that page authors access using an XML-like syntax.
>Web authors can change and edit the fixed template portions of pages without affecting the application logic. Similarly, developers can make logic changes at the component level without editing the individual pages that use the logic.
What is JSP Scriptlets?
Scriptles are: <% //java codes %> . JSP Scriptlets begins with <% and ends %> .We can embed any amount of java code in the JSP Scriptlets.JSP Engine places these code in the _jspService() method.
What is JSP Expressions?
SP Expressions start with <%= and ends with %>. Between these this you can put anything and that will converted to the String and that will be displayed.
<%="Hello Expressions!" %>
What are Decalarations?
Declarations are similar to variable declarations in Java.Variables are defined for subsequent use in expressions or scriptlets. Declarations are defined between <%! and %>.
< %! int a=0; %>
What are Directives?
Directives are instructions that are processed by the JSP engine when the page is compiled to a servlet. Directives are used to set page-level instructions, insert data from external files, and specify custom tag libraries. Directives are defined between < %@ and % >.
< %@ page language=="java" imports=="java.io.*" % >
< %@ include file=="banner.html" % >
How to declare instance or global variables in jsp?
Instance variables should be declared inside the declaration part. The variables declared with JSP declaration element will be shared by all requests to the jsp page.
< %@ page language=="java" contentType="text/html"% >
< %! int a=0; %>
What are the different types of directives available in JSP?
The following are the different types of directives:
1 .include directive : used to include a file and merges the content of the file with the current page
2 .page directive : used to define page specific attributes like scripting language, error page, buffer, thread safety, etc
3 .taglib : used to declare a custom tag library which is used in the page.
Can I create XML pages using JSP technology?
Yes. The JSP specification does support creation of XML documents. For simple XML generation, the XML tags may be included as static template portions of the JSP page. Dynamic generation of XML tags occurs through bean components or custom tags that generate XML output. See the white paper Developing XML Solutions with JavaServer Pages Technology (PDF) for details. What are JSP actions?
JSP actions are executed when a JSP page is requested. Action are inserted in the jsp page using XML syntax to control the behavior of the servlet engine. Using action, we can dynamically insert a file, reuse bean components, forward the user to another page, or generate HTML for the Java plugin. Some of the available actions are as follows:
<jsp:include> - include a file at the time the page is requested.
<jsp:useBean> - find or instantiate a JavaBean.
<jsp:setProperty> - set the property of a JavaBean.
<jsp:getProperty> - insert the property of a JavaBean into the output.
<jsp:forward> - forward the requester to a new page.
<jsp:plugin> - generate browser-specific code that makes an OBJECT or EMBED tag for the Java plugin.
What is meant by implicit objects? And what are they?
Implicit objects are those objects which are avaiable by default. These objects are instances of classes defined by the JSP specification. These objects could be used within the jsp page without being declared.
The following are the implicit jsp objects:
1. application
2. page
3. request
4. response
5. session
6. exception
7. out
8. config
9. pageContext
How do I use JavaBeans components (beans) from a JSP page?
The JSP specification includes standard tags for bean use and manipulation. The <jsp:useBean> tag creates an instance of a specific JavaBean class. If the instance already exists, it is retrieved. Otherwise, a new instance of the bean is created. The <jsp:setProperty> and <jsp:getProperty> tags let you manipulate properties of a specific bean.
What is the difference between jsp:include; and %@include:
Both are used to insert files into a JSP page.
<%@include:> is a directive which statically inserts the file at the time the JSP page is translated into a servlet.
<jsp:include> is an action which dynamically inserts the file at the time the page is requested.
What is the difference between forward and sendRedirect?
Both requestDispatcher.forward() and response.sendRedirect() is used to redirect to new url.
forward is an internal redirection of user request within the web container to a new URL without the knowledge of the user(browser). The request object and the http headers remain intact.
sendRedirect is normally an external redirection of user request outside the web container. sendRedirect sends response header back to the browser with the new URL. The browser send the request to the new URL with fresh http headers. sendRedirect is slower than forward because it involves extra server call.
How is Java Server Pages different from Active Server Pages?
JSP is a community driven specification whereas ASP is a similar proprietary technology from Microsoft. In JSP, the dynamic part is written in Java, not Visual Basic or other MS-specific language. JSP is portable to other operating systems and non-Microsoft Web servers whereas it is not possible with ASP.Can't Javascript be used to generate dynamic content rather than JSP?
JavaScript can be used to generate dynamic content on the client browser. But it can handle only handles situations where the dynamic information is based on the client's environment. It will not able to harness server side information directly.
Pre->Collection | Next->Servlet |
*****Please feel free to give feedback at shrawan.iitg@gmail.com and comments below *****
No comments:
Post a Comment