What is difference between custom JSP tags and beans?
JSP Interview Questions and Answers
(Continued from previous question...)
2. What is difference between custom JSP tags and beans?
Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. To use custom JSP tags, you need to define three separate components:
1. the tag handler class that defines the tag\'s behavior
2. the tag library descriptor file that maps the XML element names to the tag implementations
3. the JSP file that uses the tag library
When the first two components are done, you can use the tag by using taglib directive:
<%@ taglib uri="xxx.tld" prefix="..." %>
Then you are ready to use the tags you defined. Let's say the tag prefix is test:
MyJSPTag or
JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags
to declare a bean and use
to set value of the bean class and use
to get value of the bean class.
<%=identifier.getclassField() %>
Custom tags and beans accomplish the same goals -- encapsulating complex behavior into simple and accessible forms. There are several differences:
Custom tags can manipulate JSP content; beans cannot.
Complex operations can be reduced to a significantly simpler form with custom tags than with beans.
Custom tags require quite a bit more work to set up than do beans.
Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page.
Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.
(Continued on next question...)
Other Interview Questions
- What is a JSP and what is it used for?
- What is difference between custom JSP tags and beans?
- What are the two kinds of comments in JSP and what's the difference between them.
- What is JSP technology?
- What is JSP page?
- What are the implicit objects?
- How many JSP scripting elements and what are they?
- Why are JSP pages the preferred API for creating a web-based client program?
- Is JSP technology extensible?
- Can we use the constructor, instead of init(), to initialize servlet?
- How can a servlet refresh automatically if some new data has entered the database?
- The code in a finally clause will never fail to execute, right?
- How many messaging models do JMS provide for and what are they?
- What information is needed to create a TCP Socket?
- What Class.forName will do while loading drivers?
- How to Retrieve Warnings?
- How many JSP scripting elements are there and what are they?
- In the Servlet 2.4 specification SingleThreadModel has been deprecated, why?
- What are stored procedures? How is it useful?
- How do I include static files within a JSP page?
- Why does JComponent have add() and remove() methods but Component does not?
- How can I enable session tracking for JSP pages if the browser has disabled cookies?
- How do I prevent the output of my JSP or Servlet pages from being cached by the browser?
- How do you restrict page errors display in the JSP page?
- What JSP lifecycle methods can I override?
- How do I perform browser redirection from a JSP page?
- How does JSP handle run-time exceptions?
- How do I use comments within a JSP page?
- Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?
- How can I implement a thread-safe JSP page?
- How can I declare methods within my JSP page?
- Can I stop JSP execution while in the midst of processing a request?
- Can a JSP page process HTML FORM data?
- Is there a way to reference the "this" variable within a JSP page?
- How do you pass control from one JSP page to another?
- Is there a way I can set the inactivity lease period on a per-session basis?
- How does a servlet communicate with a JSP page?
- How do I include static files within a JSP page?
- Can you make use of a ServletOutputStream object from within a JSP page?
- Can a JSP page instantiate a serialized bean?
- What is JSP?
- How do I mix JSP and SSI #include?
- How do I mix JSP and SSI #include? What is the difference between include directive & jsp:include action?
- How do you prevent the Creation of a Session in a JSP Page and why? What is the difference between include directive & jsp:include action?
- How do I use a scriptlet to initialize a newly instantiated bean?
- How can I set a cookie and delete a cookie from within a JSP page?
- How do you connect to the database from JSP?
- What is the page directive is used to prevent a JSP page from automatically creating a session?
- How do you delete a Cookie within a JSP?
- Can we implement an interface in a JSP?
- What is the difference between ServletContext and PageContext?
- What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?
- How to pass information from JSP to included JSP?
- How is JSP include directive different from JSP include action.
- Can we override the jspInit(), _jspService() and jspDestroy() methods?
- Why is _jspService() method starting with an '_' while other life cycle methods do not?
- Explain the life cycle of JSP?
- What happens when a page is statically included in another JSP page?
- A JSP page, include.jsp, has a instance variable "int a", now this page is statically included in another JSP page, index.jsp, which has a instance variable "int a" declared. What happens when the index.jsp page is requested by the client?
- Can you override jspInit() method? If yes, In which cases?
- What is the difference between directive include and jsp include?
- What is the difference between RequestDispatcher and sendRedirect?
- How does JSP handle runtime exceptions?
- How can my application get to know when a HttpSession is removed?
|