JSP - SPLessons

JSP Expression Tag

Chapter 31

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

JSP Expression Tag

JSP Expression Tag

shape Description

JSP Expression Tag prints the results of the program. When one writes code inside the expression tag, the response is printed on output stream. So no need to write out.print(). JSP expression tag is mainly used for printing the values of variables and methods. The JSP Expression tag transforms the code into an expression statement that converts into a value in the form of string object and insert into the implicit output object.


<%=  statement %>

shape Example

Following is the best and simple example for JSP Expression Tag to printing the username using the expression tag.


	  <form action="welcomeexp.jsp">  
		<input type="text" name="uname"></br>  
		<input type="submit" value="go">  

Here the developer just created text box to enter the user name and also created the submit button that is go.

	 <%= "Welcome to "+request.getParameter("uname") %>  

The request.getParameter() method is used to retrieve the data.

Output will be as follows, where created one text field, when enter the text in the field another page will be opened.

After enter the message, output will be as welcome to followed by message text.

With expressions in JSP, the result of assessing the expression are changed over to a string and straight forwardly included inside the yield page. Normally expressions are utilized to show straight forward estimations of variables or return values by summoning a bean’s getter methods. JSP expressions start inside labels and do exclude semicolons.
However, scriptlet can contain any number of dialect articulations, variable or method declarations, or expressions that are substantial in the page scripting dialect. Inside scriptlet tags, one can proclaim variables or strategies to utilize later in the record, compose expressions legitimate in the page scripting language.


shape Key Points

  • Expression tag is used to estimate java expression at request process.
  • JSP expression tag is mainly used for printing the values of variables and methods.