JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy
  • Contact Us

JSTL Function fn:replace()

March 7, 2014 by Krishna Srinivasan Leave a Comment

<fn:replace()> is a string function. The function replace is used to replace the entered string with specified string. The <fn:replace()> function replaces the existing string with another string.

Syntax of JSTL Function <fn:replace()>

[code lang=”html”]
String fn:replace(String input, existing String, String replace_with)
[/code]

Example of JSTL Function <fn:replace()>

Following example demonstrate the working of <fn:replace()> function. In this example we replace the string Welcome to Javabeat with the new string as Hello JavaBeat.net.

[code lang=”html”]
&lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot;%&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/functions&quot; prefix=&quot;fn&quot;%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;JSTL fn:replace() example&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;c:set var=&quot;author&quot; value=&quot;Welcome to Javabeat&quot; /&gt;
&lt;p&gt;
String &lt;b&gt;Welcome to Javabeat&lt;/b&gt; changed to &lt;b&gt;Hello JavaBeat.net&lt;/b&gt;
&lt;/p&gt;
${fn:replace(author, &quot;Welcome to Javabeat&quot;, &quot;Hello JavaBeat.net&quot;)}
&lt;/body&gt;
[/code]

Steps for Execution

  • Save this file as example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server

Output

When the execution process is completed successfully we will get the following output :
jstl_fnreplace_demo

 

Previous Tutorial :  JSTL Function fn:trim()

Filed Under: Java EE Tagged With: JSTL Tutorials

JSTL Function fn:trim()

March 7, 2014 by Krishna Srinivasan Leave a Comment

Function <fn: trim ()> is used to remove leading and trailing white spaces, tabs from the start and end of the string. The function returns the string after removing white spaces from both points of the input string.

Syntax Of <fn: trim ()> Tag

[code lang=”html”]
String fn: trim (string)
[/code]

Example

[code lang=”html”]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL fn:trim()</title>
</head>
<body>

<c:set var="str" value=" Hello world!!! Welcome to JavaBeat. "></c:set>
<p>Trimmed String is:</p>
<c:out value="${fn:trim(str)}"></c:out>

</body>
</html>
[/code]

Steps for Execution

  • Save the file as trimExample.jsp in eclipse IDE.
  • Now select the jsp file, right click on mouse and select Run as -> Run on Server.

Output

After successful execution of the program we will get the following result:
fn_trim

 

Previous Tutorial :  JSTL Function fn:toUpperCase() :: Next Tutorial : JSTL Function fn:replace()

Filed Under: Java EE Tagged With: JSTL Tutorials

JSTL Function fn:toUpperCase()

March 7, 2014 by Krishna Srinivasan Leave a Comment

The <fn: toUpperCase> is function of JSTL which is used to returns all the characters of string to upper case. It converts input string to an upper case string. The string which needs to be changed to upper case is passed as argument and converted string is being returned by the function.

Syntax Of <fn: toUpperCase> Tag

[code lang=”html”]
String fn: toUpperCase(string)
[/code]

Example

[code lang=”html”]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL fn:toUpperCase()</title>
</head>
<body>

<c:set var="str" value="welcome to javabeat"></c:set>
<c:out value="${fn:toUpperCase(str)}"></c:out>

</body>
</html>
[/code]

Here the text “welcome to javabeat” is converted to uppercase.

Steps for Execution

  • Save the file as toUpperCaseExample.jsp in eclipse IDE.
  • Now select the jsp file, right click on mouse and select Run as -> Run on Server.

Output

After successful execution of the program we will get the following result:
fn_uppercase

 

Previous Tutorial :  JSTL Function fn:toLowerCase()  :: Next Tutorial : JSTL Function fn:trim()

Filed Under: Java EE Tagged With: JSTL Tutorials

JSTL Function fn:toLowerCase()

March 7, 2014 by Krishna Srinivasan Leave a Comment

The <fn: toLowerCase> is function of JSTL which is used to returns all the characters of string to lower case. It converts input string to a lower case string. The string which needs to be changed to lower case is passed as argument and converted string is being returned by the function.

Syntax Of <fn: toLowerCase> Tag

[code lang=”html”]
String fn: toLowerCase(string)
[/code]

Example

[code lang=”html”]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL fn:toLowerCase()</title>
</head>
<body>

<c:set var="str" value="WELCOME TO JAVABEAT"></c:set>
<c:out value="${fn:toLowerCase(str)}"></c:out>

</body>
</html>
[/code]

Here we are converting the text “WELCOME TO JAVABEAT” to lower case.

Steps for Execution

  • Save the file as toLowerCaseExample.jsp in eclipse IDE.
  • Now select the jsp file, right click on mouse and select Run as -> Run on Server.

Output

After successful execution of the program we will get the following result:
fn_lowercase

 

Previous Tutorial :  JSTL Function fn:length() :: Next Tutorial : JSTL Function fn:toUpperCase()

Filed Under: Java EE Tagged With: JSTL Tutorials

JSTL Function fn:length()

March 7, 2014 by Krishna Srinivasan Leave a Comment

The function <fn:length()> is the string function. This function used to find out the length of the entered string. This function displays the number of characters entered in the specified string.

Syntax of Function <fn:length()>

[code lang=”html”]
int length(Object)
[/code]

Example of Function <fn:length()>

[code lang=”html”]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head>
<title>JSTL fn:length() example</title>
</head>
<body>
<c:set var="string1" value="JavaBeat" />
<c:set var="string2" value="welcome to JavaBeat.net" />
Length of word JavaBeat is: ${fn:length(string1)}
<br>
<br> Length of word welcome to JavaBeat.net is:
${fn:length(string2)}
<br>
<br>

</body>
</html>
[/code]

Steps for Execution

  • Save this file as example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server

Output

When the execution process is completed successfully we will get the following output :
output of jstl function length

Previous Tutorial :  JSTL Function fn:substring()  :: Next Tutorial : JSTL Function fn:toLowerCase()

Filed Under: Java EE Tagged With: JSTL Tutorials

JSTL Function fn:substring()

March 5, 2014 by Krishna Srinivasan Leave a Comment

The <fn:substring()> is the string function of JSP Standard Tag Library(JSTL). This function is used to extract a string specified using the two index values that is start and end value. This function returns a substring with a specified position.

Syntax of JSTL Function <fn:substring()>

[code lang=”html”]
String fn:substring(String , int , int)
[/code]

Example

[code lang=”html”]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<c:set var="str" value="welcome to javabeat site" />
${fn:substring(str,10,24)}

</body>
</html>
[/code]

Details of the Code

  • <c:set var=”str” value=”welcome to javabeat site” /> tag is used to set variable name and to display result in the output using value attribute.
  • ${fn:substring(str,10,24)} is used to extract a string specified using the two index values that is start and end value.

Steps for Execution

  • Save the file as substring_example.jsp in eclipse IDE.
  • Now select the jsp file, right click on mouse and select Run as -> Run on Server.

Output

After successful execution of the program we will get the following result:
fn_substring

Previous Tutorial :  JSTL Function fn:startsWith()  :: Next Tutorial : JSTL Function fn:length()

Filed Under: Java EE Tagged With: JSTL Tutorials

JSTL Function fn:startsWith()

March 5, 2014 by Krishna Srinivasan Leave a Comment

The function <fn:startsWith()> is a string function of JSTL. This function is used to check the input string starts with the given specified character or prefix. It returns true if it contains specified character otherwise returns false.

Syntax of JSTL Function <fn:startsWith()>

[code lang=”html”]
boolean:fn:startsWith (java.lang.String, java.lang.String)
[/code]

Example of JSTL Function <fn:startsWith()>

[code lang=”html”]
<%@ 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:startsWith</title>
</head>
<body>

<p>
String "JavaBeat" starts with "J":
</p>
${fn:startsWith("JavaBeat",’J’)}

</body>
</html>
[/code]

Details of the Code

  • ${fn:startsWith(“JavaBeat”,’J’)} tag is used to check if the string starts with the given prefix. It returns true if result found correctly otherwise false.

Steps for Execution

  • Save this file as startsWith_example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server

Output

When the execution process completed successfully we will get the following output:
fn_startsWith

Previous Tutorial :  JSTL Function fn:split()  :: Next Tutorial : JSTL Function fn:substring()

Filed Under: Java EE Tagged With: JSTL Tutorials

JSTL Function fn:split()

March 5, 2014 by Krishna Srinivasan Leave a Comment

The JSTL Function <fn:split()> is the string function. This function is used to split or separate the string with specified delimiter(separator). JSTL Function <fn:split()> helps to split or separate a specified string into an array of substring.

Syntax of JSTL Function <fn:split()>

[code lang=”html”]
java.lang.String[] split(java.lang.String, java.lang.String)
[/code]

Example of JSTL Function <fn:split()>

[code lang=”html”]
<%@ 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"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>fn:split Demo</title>
</head>
<body>
<h1>Example of Function fn:split()</h1>
<c:set var="name" value="welcome-to-JavaBeat" />
<c:set var="splitName" value="${fn:split(name,’-‘)}" />
<c:set var="joinedName" value="${fn:join(splitName,’ ‘)}" />
<p>Name before split: <br><br><b>${name}</b></p>
<p>Name after split: <br><br><b>${joinedName}</b></p>
</body>
</html>
[/code]

Details of the Code

  • <c:set var=”name”> tag is used to set the variable name which we want to display in the output.
  • < c:set var=”splitName” value=”${fn:split(name,’-‘)}”> this line of code used to display the name separated by a specified separator.
  • Name before split: ${name} this line of code displays the name before it split.
  • after split:joinedName} this line of code displays the name after splitting.

Steps for Execution

  • Click on the jsp File
  • Right click on mouse and select run as ->click run on server
  • The simple way for execute the program on eclipse is to use Ctrl+F11 key then click on select your browser option and click on finish

Output

When the execution process completed successfully we will get the output on eclipse browse as follows:
output of jstl function fn split

Previous Tutorial :  JSTL Function fn:join()  :: Next Tutorial : JSTL Function fn:startsWith()

Filed Under: Java EE Tagged With: JSTL Tutorials

JSTL Function fn:join()

March 5, 2014 by Krishna Srinivasan Leave a Comment

The <fn:join()> is a string function of JSP Standard tag Library(JSTL).This function is used for joining all the elements of an array into a string with a specified operator and returns the output. This function returns string with all the elements of an array separated by a separator.

Syntax of <fn:join()> function

[code lang=”html”]
java.lang.String join(java.lang.String[], java.lang.String)
[/code]

Example of <fn:join()> function

[code lang=”html”]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<c:set var="str" value="mahantesh maruti" />
<c:set var="str1" value="${fn:split(str,’ ‘)}" />
<c:out value="${fn:join(str1,’-‘)}" />

</body>
</html>
[/code]

Details of the Code

  • <c:set var=”str” value=”mahantesh maruti” /> tag is used to set the value for variable into the given scope .
  • <c:set var=”str1″ value=”${fn:split(str,’ ‘)}” /> tag uses split() function to split string into an array of substrings based on given delimiter.
  • <c:out value=”${fn:join(str1,’-‘)}” /> tag is used to join the elements of array into string separated by the separator.

Steps for Execution

  • Save this file as join_example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server

Output

When the execution process completed successfully we will get the following output:
fn_join

 

Previous Tutorial :  JSTL Function fn:indexOf()  :: Next Tutorial : JSTL Function fn:split()

Filed Under: Java EE Tagged With: JSTL Tutorials

JSTL Function fn:indexOf()

March 5, 2014 by Krishna Srinivasan Leave a Comment

The <fn:indexOf()> is a string function of JSTL. This function returns the index within a string of a specified substring. This function is used to get the first occurrence of the substring in the given string. This function takes string type as arguments and returns int type.

Syntax of <fn:indexOf()> Tag

[code lang=”html”]
int indexOf(String,String)
[/code]

Example

[code lang=”html”]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<html>

<head>

<title>Example of fn:indexof tag of JSTL</title>

</head>

<body>

<form method="POST">

This will calculate the first occurance of given character/string in
the <br>specified String.

<table>

<tr>

<td>Enter Text</td>

<td><input type="text" name="text"></td>

</tr>

<tr>

<td>Search</td>

<td><input type="text" name="str"></td>

</tr>

<tr>

<td></td>

<td><input type="submit" value="search"></td>

</tr>

</table>

</form>

<c:if test="${pageContext.request.method==’POST’}">

<c:set var="text" value="${param.text}" />

<c:set var="str" value="${param.str}" />

<font size="3" color="Red"> Index of first occurance : </font>
<font size="3" color="Blue"> <c:out
value="${fn:indexOf(text,str)}" />

</font>

</c:if>

</body>

</html>
[/code]

Steps for Execution

  • Save this file as example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server

Output

When the execution process is completed successfully we will get the following output :
Suppose if we enter the string Javabeat and if we want to index of the first occurrence of the “a” then it will shows the following output.
output of jstl function fn indexOf1
When we enter the string Javabeat and if we press search button it will shows the following output:
output of jstl function fn indexOf2

Previous Tutorial :  JSTL Function fn:escapeXml()   :: Next Tutorial : JSTL Function fn:join()

Filed Under: Java EE Tagged With: JSTL Tutorials

  • 1
  • 2
  • 3
  • …
  • 6
  • Next Page »

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved