JSTL fn containsIgnoreCase Example

JSTL fn containsIgnoreCase Example


Posted in : Java Posted on : April 13, 2012 at 6:45 PM Comments : [ 0 ]

In this tutorial you will learn about the JSTL fn containsIgnoreCase function.

JSTL fn containsIgnoreCase Example

In this tutorial you will learn about the JSTL fn containsIgnoreCase function.

containsIgnoreCase function checks for the specified substring with ignoring the case of characters whether, it is present in the existing string or not. This function returns a boolean value 'true' when it is found a substring into an other string otherwise returns 'false'.

Syntax :

boolean containsIgnoreCase(java.lang.String, java.lang.String)

Example :

Here an example is being given below will demonstrate you about the JSTL functions containsIgnoreCase. In this example I have created a JSP page where I have taken a form into which took a text box to take the value as an input form the user and a submit button to submit the value. When a form will be submitted with any string value without caring the case you have entered, then string matching statement will be executed, where the entered string will be searched within the string that I have set as a constant value using the <c:set var="" value=""/> tag belongs to JSTL core tag library for this I have used the fn:containsIgnoreCase(str, str), this function returns true if the substring is matched within the string otherwise, false.

JstlFnContainsIgnoreCase.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL fn:containsIgnoreCase() Function Example</title>
</head>
<body>
<form action="JstlFnContainsIgnoreCase.jsp">
<p>Enter String in any case :
<input type="text" name="text1"/></p>
<p><input type="submit" value="submit"/>
</form>
<%if(request.getParameter("text1")!=null) 
{
%>
<c:set var="str" value="Devmanuals"/>
<p>Is the substring <b>"${param.text1}"</b> is contained into the existing
string <b>${str}</b> ? : ${fn:containsIgnoreCase(str, param.text1)}</p>

<%} %>
</body>
</html>

How to run this example

Here I am using an IDE Eclipse so I am giving the process of executing this example in perspective of Eclipse. Before executing this example you will have needed to add the following jar files :

  • jstl.jar
  • standard.jar

After adding of these jar files you may execute your program in the following ways :

  • Select JstlFnContainsIgnoreCase.jsp file of your project in Project Explorer -> RightClick -> Run As -> Run On Server -> Choose your server -> Finish.
  • On the Eclipse Editor go to your JstlFnContainsIgnoreCase.jsp -> RightClick -> Run As -> Run On Server -> Choose your server -> Finish.
  • Go to Run button look at the toolbar in green color and click -> Choose your server -> Finish.
  • A simplest way to execute the example in Eclipse is to use the CTRL+F11 key -> Run On Server -> Choose your server -> Finish

NOTE : In all of the above execution processes you may start the server first and stop the server each time after the execution if not, each time you will may prompted to a dialog box to Restart the server in Eclipse.

Output :

When the execution process will be completed successfully you will get the output on your eclipse browser as follows :

1. At first you will be prompted to enter a value in the text box following image demonstrates this process :

2. When you will click on submit button after enter a string as entered in the above image an output will be as follows :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics