Posts

JSP - Expression Language (EL)

JSP Expression Language (EL) makes it possible to easily access application data stored in JavaBeans components. JSP EL allows you to create expressions both  (a)  arithmetic and  (b)  logical. Within a JSP EL expression, you can use  integers, floating point numbers, strings, the built-in constants true and false  for boolean values, and null. Simple Syntax Typically, when you specify an attribute value in a JSP tag, you simply use a string. For example − <jsp:setProperty name = "box" property = "perimeter" value = "100"/> JSP EL allows you to specify an expression for any of these attribute values. A simple syntax for JSP EL is as follows − ${expr} Here  expr  specifies the expression itself. The most common operators in JSP EL are  .  and  [] . These two operators allow you to access various attributes of Java Beans and built-in JSP objects. For example, the above syntax  <jsp:setProperty>  tag...

JSP - Custom Tags

In this chapter, we will discuss the Custom Tags in JSP. A custom tag is a user-defined JSP language element. When a JSP page containing a custom tag is translated into a servlet, the tag is converted to operations on an object called a tag handler. The Web container then invokes those operations when the JSP page's servlet is executed. JSP tag extensions lets you create new tags that you can insert directly into a JavaServer Page. The JSP 2.0 specification introduced the Simple Tag Handlers for writing these custom tags. To write a custom tag, you can simply extend  SimpleTagSupport  class and override the  doTag()  method, where you can place your code to generate content for the tag. Create "Hello" Tag Consider you want to define a custom tag named <ex:Hello> and you want to use it in the following fashion without a body − <ex:Hello /> To create a custom JSP tag, you must first create a Java class that acts as a tag handler. Let us now cre...