What is jstl?and types of Jstl in jsp?

gm friends ! happy Sunday .  Enjoy your Sunday with beautiful Sunday love feast.

So our Today’s topic is What is JSTL? and What are the types of jstl.?

what is Jstl?

The JSP standard tag library (JSTL) represents a set of tags to simplify the jsp development.

benefits of using jstl.

1.minimize the mount of scriptlet code in a jsp.

2.avoid dumping thousands of line of code in a jsp page.

3.jsp page is simple main focus of jsp is only the presentation.

4.tag is reusable.

5.fast development jstl provides many tagsthat simplify the jsp.

6.no need to use the scriptlet tag.

7.It avoids the use of scriptlet tag.

What are the types of jsp standard tag library.?

==There are mainly 5 types of jstl tags.

Oracle created a specification for the standard tag .

1.core tag:

2.message formatting I18 N:

3.functions tag:

4.XML tag:

so now we take very simple definition for all these tags.

a very simple definition for better understanding and easy.

so the first one is

1.core tag.: this tag is used for handling variables and  looping and condition.

2.message formatting I 18 N(internationalization):-this message tag is used for handling interlization and formatting.

3.functions:there function tag is used for string manipulation and getting the sizes of a collection.

4.XML:there’s also a group of tag for Xml for parsing and setting Xml data.

5.SQL : for accessing database.

but in this article we are going to dive into only two tags that is the core tag and the function tag because  this tag is mostly used in developing the web application in jsp.

So lets get start !!—

So i am just writing the name of the few jsp core tag . I am going to write a code for all these tag so if you want to get the code  of all the jsp core tag then you can go and continue with java t point that  sites explain very nicely about all the code of jsp  core tag.

So now here are the examples of jsp core tag.

  1. catch:-  catches any throw able  to occurs in the body.
  2. choose:-conditional tag that can be used for exclusive operations  ,similar to switch statement .
  3. if:—-simple if /then condition.
  4. import:–retrieves a url  and express it contents on the page or avariable.
  5. for Each:—–Iterates over a collection of values.
  6. for tokens:-Iterates over a collection of tokens.
  7. out:——-used in scriptlets to display output, similar to <% =———-%>
  8. otherwise:—used with the choose tag to handle the else clause 
  9. param:–    adds a  parameter to a url.
  10. redirect:——redirect the browser to a new url.
  11. remove:——remove a scope variable
  12. set:–assign an expression value to a variable.
  13. url:-  defines a url with query parameters.

when:-.used with the <.choose > tag when a condition is true.

 so there are the examples of jsp core tag now we we take one example with written code.

so lets see:-

 

 

Every page that uses the core tag must use this references :

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

In the reference we use the prefix c for the jsp core tag:-

<—————————————————Example:——————–>

<html>

<title>core tag example</title>

<h3>core tag</h3>

<body>

<%

//  just create sample data normaly provided by mvc.

String [ ] cities ={“ranchi”, “delhi”,      “dumka”};

pageContext.set Attribute(“my Cities “,cities);

//here my Cities is the name of the attribute and cities is the value of this attribute.

%>

<C:foEeach                  var=  “tempcity”                          items= “${my Cities}”>

//where temp city = temp variable and my cities = name of the attribute

${temp City}

</br>

</c:forEach>

</body>

</html>

output:-

ranchi delhi dumka

so this was the code of jsp custom tag .as i said there are many core tags so you can practise on your own with the following website

www.javatpoint.com’

Now i will cover the topic of jsp function tag and their examples with code and about prefix so have a look :-

  • Every page that uses the function tags must include this reference :
  • <% @taglib  uri   =    “http://java.sun.com/jsp/jstl/functions” prefix=”fn”>
  • <————————–code example————————————————->
  • <C: set var =”data” value=”goodmorning”  />

length of the  String <b> ${data}</b>:${fn:length (data)}=  11.

//so that the length of the string “goodmorning ”  is 11.

this is the basic code now we will write the ful code of jsp function tag:

show me the code:—————————————————

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

<% @ taglib uri=”http://java.sun.com/jsp/jstl/core=”   prefix=”fn” %>  //fn for function tag

<html>

<body>

<C:Set var=”data ”   value=”good morning”/>

Length of the String <b> ${data} </b>: $ {   fn:   length (data)   }

Uppercase version of the string <b>${data}  </b> :${fn:    to    uppercase(data)   }

 

</C:Set>

</body>

</html>

so the output of this code is:

length of the string goodmorning is: 11.

uppercase version of the string goodmorning is:GOODMORNING

 

THANK YOU :——–

Hope you will like my article and get benefited keep practising and keep coding.

 

 

 

 

 

 

 

 

 

 

 

 

 

what is Jsp? types of scripting elements in Jsp.

 

<———————————————————-J2EE—————————->

GM friends how are you ?

So  today we are going to learn about jsp (component of advance java)  and expression tag in jsp and and we are going to learn about a little about jstl(java standard tag library.)

J2EE =java to enterprise edition.

j2ee module is used  to develop the following applications.

1.web applications .

 

2.distributed  applications.

3.Enterprise applications.

4.N- tier applications.

<———————————- JSP————————->

JSP is a dynamica progrmming language .

It is capable of making simple program to complex program.

An HTML page with some java code sprinkled in jsp.

JSP is processed on the server. (tomcat,glassfish ,javaserver etc)

result of java code included in html returned to browser.

A jsp consists  of html tag and jsp tag.

Jsp is a technology used to create web applications just like servlet technology.

IT can be thought  as an extension of servlet because more functionality than servlets. such as expression  language ,jstl etc.

the JSp pages are easier to maintain then servlet because we can separate designing  and development .

IT provides same additional feature such as expression language ,custom tags etc.

There are three types of  JSP expression.

  1. JSP expression    <%=   some java expression %>

2.  JSP Scriptlet =  <%= some java code: 1  to many lines %>

3    .JSP declaration = <%!  variable  or method declaration %>

JSP expression:———————————————————–

<html>

<body>

<h1>converting a string to uppercase:</h1>

<% =  new String(“hello world”).to uppercase()%>

</body>

</html>

———————————————————————————————-

output:- HELLO WORLD

JSP Scriptlets:———————————————————————-

insert 1 to many lines of java code.

to include content in the page use: out.println.

example:——————————

<html>

<body>

<h1>jsp scriptlet </h1>

<%

for (int i=1;i<=5;i++)

{

out.println(“the numbers in the loop”+i);

}

%>

</body>

</html>

output:-the numbers in the loop 1

the numbers in the loop 2

the numbers in the loop 3

the numbers in the loop 4

the numbers in the loop 5

JSP declarations:———————————————————————————————————————————————————————–>

Declare a  method in the jsp tag.

Call the method in the same jsp page.

the declarations tag .

<% !

write some code



%>

example:———————————————————————————

<html>

<body>

<h3>declarations tag</h3>

<%!

String make it lower(String data)

{

return data to Lowercase();

}

%>

Lower case”HELLO WORLD”-

<%=  makeitLower(“hello world”) %>

</body>

</html>

output:—-

declaration tag

hello world

 

thank you hope you will like this article and get benefited.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

How to see the current date in jsp.?

firstly open the eclipse IDE  and  create new project .

name that project and click finish.

goto web  content and create a new file  name helloword.jsp.

and click ok.

and now create and write the code.

<html>

<body>

<h3>hello word</h3>

the time on the server is

<% = new java.util.Date() %>

//create new date object

//output indulged in html page

</body>

</html>

output:

hello world of java

the time on the server is monday 10:25 am 2020.