World class Hard Drive Recovery and renowned raid recovery services

WestNIC provides reliable web hosting services

Site navigation below

This FAQ is part of the Code Style Help and FAQ section. Use the help request form below if your question is not answered here, but make sure you are asking the right question first.

Subscribe to this FAQ: RSS news feed

FAQ search

Understanding JSP includes

Q: What's the difference between the include directive and action element?

A: The @page include directive in a JSP document is resolved at page translation time, when the servlet container converts the JSP into Java source code and then compiles it. The included file contents may be static HTML fragments and optionally include their own JSP tags and scripts. Each included file is inserted into the flow of the parent JSP document as if it were part of the original, so it is a good way of placing template-style code fragments into numerous pages.

Premium Content: Follow this link for subscription information More details available to subscribers:
What's the difference between the include directive and action element?

Q: How many servlets are created by the include directive or jsp:include?

A: When you use the jsp:include tag, the text of a file is inserted into the output stream of the JSP servlet at the point the tag occurs. This insertion occurs at request time and is not parsed for JSP script content, the file content is just copied to the output stream.

Premium Content: Follow this link for subscription information More details available to subscribers:
How many servlets are created by the include directive or jsp:include?

Q: Can I instantiate an object without using the @ page include tag?

A: The only way to instantiate a class in an external package is to declare it in an @ page include directive, followed by a constructor statement. Bear in mind that your JSP will be compiled into servlet source code and then a servlet class in turn. The page include directive is translated into an import statement in the servlet source and is the only way to place such statements in the source. If the import statement is not present the servlet will not compile.

As with all Java programs, classes in the package java.lang are imported implicitly, so it is possible to instantiate objects in this package without a page include directive.

Tag libraries

Q: What is the basic concept of taglibs?

A: Tag libraries define a set of JSP tags that may be used in a Web application. The tag library descriptor file is used to declare the tags that belong to a library and the attributes and values they may use. The tag library descriptor is loaded by the servlet container when it starts up so that it can insert the relevant code into JSP documents when they are compiled into servlets.

Tag libraries enable the inclusion of relatively complex Java processing using a syntax that is very similar to HTML, that does not require special knowledge of Java language or programming. Tag libraries can also be re-used in multiple Web applications, hence Sun's Java Standard Tag Library (JSTL).

Q: What's the difference between standard and custom tag libraries?

A: The main difference between the two is that the Java Standard Tag Library (JSTL) is designed for general purposes and custom libraries are written for specific applications.

Premium Content: Follow this link for subscription information More details available to subscribers:
What's the difference between standard and custom tag libraries?

Q: I get "No such tag ... with prefix Hello", what's up?

A: To configure Tomcat to handle your custom tags, you must create an XML format Tag Library Descriptor (TLD) file and configure the application's web.xml file to load it. A minimal tag library descriptor is given below.

Premium Content: Follow this link for subscription information More details available to subscribers:
I get "No such tag ... with prefix Hello", what's up?

Q: I get "attribute binding does not accept any expressions"!

A: This error means that a tag attribute in your Tag Library Definition (TLD) is configured to expect a literal attribute value, not a runtime expression, but your JSP document is attempting to pass an expression to the tag attribute. Look up the tag identified in the stack trace and check the value attributed to the element on the relevant line of your JSP document. To fix the problem you have two options, as follows:

Premium Content: Follow this link for subscription information More details available to subscribers:
I get "attribute binding does not accept any expressions"!

Help request

Use the form below to submit a help request or general enquiry about the Code Style Web site. Read our guidelines on asking the right questions first.

Information: Your email address will not be mis-used. If you include your address you may be sent a personal reply, you will not be added to any mailing list unless you request it. Read the site privacy statement for details.

Add this page to your chosen social bookmarking service

Style warning - please read

Home · CSS · Java · Javascript · HTML · Help · Log