<c:out>

This tag can be used to print template text and expressions to the jsp.
Form 1:

<c: out value = "Java2learn"/>

It prints Java2learn to the jsp.

<c: out value = "${param.uname}"/>

It prints the value of request parameter uname to the jsp.

Form 2:

<c: out value = "${param.uname}" default = "GUEST"/>

If the main value is not available or it evaluates to null then default value will be printed.

out.jsp:

 <% @ page is EL Ignored ="false" %>
 <% @ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
 <h1> hello….<c:out value = "${param.uname}" default = "GUEST"/>

Attributes of <c:out>

  1. Value:It is the mandatory attribute and it is for providing original value.
  2. Default:It is optional attribute and it is to provide default value. jsp engine considers it’s value iff the value attribute evaluates to null.
  3. Escape xml:

<c:set>

Form1:
We can use <c:set> to set the specified attribute in a particular scope as follows:

<c: set var = "x" value = "SCJP" scope = "request"/>

Scope attribute is optional and default scope is page.

<c: set var = "x" value = "10" scope= "request"/>
<c: set var = "y" value = "20" scope= "request"/>
<c: set var = "sum" value = "${x+y}" scope= "session"/>
The sum is <c: out value = "${sum}"/>

Form2:
We can use <c:set> to set properties of bean and map objects.
For this we have to use target attribute.

<c: set target = "customer" property = "mail" value  = "${param.umail}"/>

Attributes of <c: set>

  1. var
  2. value
  3. scope
  4. property
  5. target
  6. value

<c:remove>

To remove attributes present in a specified scope.

<c:remove var ="x" scope = "request"/>

Attributes of <c:remove>

This tag contain the following two attributes

  1. Var: the name of the attribute
  2. scope: the scope in which the attribute present

If the scope attribute is not specified then jsp engine first search in the page scope if it is available then it will remove that attribute. If it is not available then jsp engine searches in request scope followed by session and application scope.

Example:

<c: set var = "x" value = "10" scope= "request"/>
<c: set var = "y" value = "20" scope= "request"/>
<c: set var = "result" value = "${x*y}" scope= "session"/>
<c: out value= "${result}" default = "8888"/> <br>
<c:remove var ="x"/>
<c:remove var="y"/>
<c:remove var= "result"/>
<c:out value = "${result}" default = "9999"/>

output:
200
9999

<c:catch>

This can be used to catch an exception with in the jsp instead of forwarding to the error page.

The risky code we have place as the body of
<c:catch> is

<c:catch>
Risky code
</c: catch>

If an exception raised in the risky code this tag supers that exception and reset of the jsp will be executed normally.
We can capture the raised exception by using var attribute which is the page scoped attribute.
catch.jsp:

<% @ page is EL Ignored = "false" %>
<% @ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<h1>
Username : ${param.uname}<br>
<c:catch var = "c">
<%
int age = Integer.parseInt(requet.get parameter("uage");
%>
Age:${param.uage}<br>
</c:catch>

<c:if test = "${c!=null}">
 Oops…exception raised:${c}<br>
</c:if>
User Height : ${param.uheight}
</h1>

http://localhost:8080/jspl/catch.jsp? Uname =Ramesh&uage =10&uheight=5.3
User name:Ramesh
Age:10
User height+ 5.3

http://localhost:8080/jspl/catch.jsp? Uname =Harold & uage =ten & uheight =5.3
User.name:Harold
Oops..exception raised:java.lang.NumberFormatException for Input string “ten”
User height : 5.3

Summary of general purpose tags:

Tag Description Attributes
<c:out> To write template text and expression to the jsp. value,default,escapeXml
<c:set> To set attributes,map and boolean properties var,value,scope,target,property
<c:remove> To remove attributes present in the specified scope var,scope
<c:catch> For surpressing an exception and to continue rest of the jsp normallt var