From the Following; which we don't include in simple tag while creating JSP custom tags:
- AStart of tag
- BEnd of tag
- CAttributes
- DNone of these
A simple custom tag has only a start and end tag, with no body and no attributes.
MCQs, short and long questions from lecture 38.Lecture 38 ki MCQs, short aur long sawal.
3 MCQs · 19 short · 3 long questions · 3 MCQs from past papers3 MCQs · 19 short · 3 long sawal · 3 MCQs past papers se
From the Following; which we don't include in simple tag while creating JSP custom tags:
A simple custom tag has only a start and end tag, with no body and no attributes.
Which of the following is not included in simple tag while creating JSP custom tags?
A simple custom tag has only a start and end tag, with no body and no attributes.
Which information a Tag Library Descriptor (.tld) file specifies?
A TLD lists library and JSP versions, each tag's name, handler class and attributes.
No MCQs match this filter.Is filter mein koi MCQ nahi.
Write the name of three types of Custom Tags?
1. Simple tag (no attributes, no body). 2. Tag with attributes. 3. Tag with body.
Why we use taglib?
The taglib directive, <%@ taglib uri="..." prefix="..." %>, tells the JSP which tag library (custom tags or JSTL) it uses, where the tag library descriptor is (uri) and which prefix identifies its tags. It lets pages use custom tags instead of Java code, so logic is reused and pages stay clean.
Custom tags type
1. Simple tag (no attributes, no body), e.g. <my:hello/> 2. Tag with attribute(s), e.g. <my:hello name="ali"/> 3. Tag with body, e.g. <my:bold>text</my:bold>
Custom tag?
A custom tag is a user-defined JSP tag (component) that performs a certain action. Its behaviour is written in a Java tag handler class, it is described in a TLD file, and it is used in JSP through a taglib directive, e.g. <mytag:hello/>.
identify the following tag: <studenttagstudy> </studenttagstudy>
It is written with a start tag and an end tag, which is the form of a tag with body (the body content goes between the two tags; here it is empty). It has no attributes.
Being a java front end developer, write the characteristics of tag with body custom tag and also give example?
A tag with body has a start tag and an end tag, may have attributes, and has body content enclosed between the tags that the tag handler can process (e.g. with getJspBody().invoke(null)). Example: <vu:bold>Welcome to VU</vu:bold>
Write a single line to include a page "vuHome.java" using custom tags. You can use any name for tag but mention which you have chosen for which tag element.
Chosen names: prefix vh, tag name vuhome, handler class vu.VuHomeTag (declared in the TLD under <tag><name>vuhome</name><tag-class>vu.VuHomeTag</tag-class><body-content>empty</body-content></tag>). After the taglib directive <%@ taglib uri="/WEB-INF/tlds/customtags.tld" prefix="vh" %>, the single line is: <vh:vuhome />
Being a java web developer you know each tag handler class must inherit from another class. What is the name of that class?
SimpleTagSupport (javax.servlet.jsp.tagext.SimpleTagSupport), which already implements the SimpleTag interface; the handler overrides doTag().
Why do we use doTag() method in tag handler class?
doTag() is the method of a simple tag handler (SimpleTagSupport) in which the tag's functionality is written. We override it, and the JSP container calls it when it processes the custom tag in the page, so whatever doTag() writes (for example through getJspContext().getOut()) appears in place of the tag.
Advantages of using Custom Tags?
Advantages of custom tags: - They separate processing logic from presentation and remove scriptlets from JSP pages. - They have an HTML-like syntax that page designers can use without knowing Java. - They are reusable in many pages, which saves development and testing time. - They can be customized with attributes and body content. - They have access to JSP implicit objects such as out and request.
Define type of <jsp:studenttag.study> </jsp:studenttag.study>
It is a custom tag with prefix and name, written with an opening and a closing tag, but it has no attributes and no body content, so it is used like a simple tag (without attributes or body).
Write three types of custom tags
Three types of custom tags: 1. Simple tag: a tag without body and without attributes, for example <mytag:hello/>. 2. Tag with attributes, for example <mytag:hello name="ali"/>. 3. Tag with body, for example <mytag:hello>body text</mytag:hello>.
Information present in .tld file?
A tag library descriptor (.tld) is an XML document that describes a custom tag library for the JSP container. It contains, for example: - tag library version (tlib-version) - JSP version (jsp-version) - short name of the library - each tag's name - tag handler class name (tag-class) - body content type - attribute names and whether they are required.
Benefits of a custom tag
Advantages of custom tags: - They separate processing logic from presentation and remove scriptlets from JSP pages. - They have an HTML-like syntax that page designers can use without knowing Java. - They are reusable in many pages, which saves development and testing time. - They can be customized with attributes and body content. - They have access to JSP implicit objects such as out and request.
Which information is present in (.tld) file? Write any five.
A tag library descriptor (.tld) is an XML document that describes a custom tag library for the JSP container. It contains, for example: - tag library version (tlib-version) - JSP version (jsp-version) - short name of the library - each tag's name - tag handler class name (tag-class) - body content type - attribute names and whether they are required.
Write a single line to include a page “vuHome.java” using custom tags. You can use any name for tags but mention which name you have chosen for which tag element.
For example: <vu:include page="vuHome.java" /> Here vu is the prefix (declared with the taglib directive), include is the tag name, and page is the attribute that gives the file to include.
Write a statement to use tag library "StudentInfo.tld" with prefix "student".
<%@ taglib uri="/WEB-INF/tlds/StudentInfo.tld" prefix="student" %>
Being a java front end web developer, write the characteristics of tag with body custom tag and also give example.
A tag with body has a start tag and an end tag with content between them; the tag handler can include, skip or process that body (and may also take attributes). Example: <mytag:bold>Hello</mytag:bold>, where the handler prints the body text in bold.
Custom tags have three forms. Write the name of each form.
1. Simple tag (a tag without body and without attributes), e.g. <mytag:hello /> 2. Tag with attributes, e.g. <mytag:hello name="ali" /> 3. Tag with body, e.g. <mytag:hello> some body </mytag:hello>
What type of information present in(.tld) file? Mension any five.
A TLD (tag library descriptor) is an XML file that describes a tag library: 1. tlib-version (library version), 2. short-name (preferred prefix), 3. uri of the library, and for each tag: 4. name of the tag, 5. tag-class (fully qualified handler class), 6. body-content (empty, scriptless, tagdependent), 7. attribute entries with name, required and rtexprvalue, plus description and jsp-version.
Write full code of using custom tag, overriding doTag() method, which will print “welcome to custom tag.”
Tag handler class (WEB-INF/classes/vu/WelcomeTagHandler.java): package vu; import java.io.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class WelcomeTagHandler extends SimpleTagSupport { public void doTag() throws JspException, IOException { JspWriter out = getJspContext().getOut(); out.print("welcome to custom tag."); } } TLD file (WEB-INF/tlds/mytaglibrary.tld): <taglib> <tlib-version>1.0</tlib-version> <jsp-version>2.0</jsp-version> <short-name>mytag</short-name> <tag> <name>welcome</name> <tag-class>vu.WelcomeTagHandler</tag-class> <body-content>empty</body-content> </tag> </taglib> JSP page: <%@ taglib uri="/WEB-INF/tlds/mytaglibrary.tld" prefix="mytag" %> <html><body> <mytag:welcome /> </body></html>
Which type of information is present in (.tld) file? Mention any five.
A TLD file contains: the tag library version; the JSP version required; the short name (preferred prefix) and URI of the library; for each tag its name and the tag handler class; the body content type (empty, JSP, scriptless or tagdependent); and each attribute's name, whether it is required, and whether it accepts runtime expressions (rtexprvalue).