JSP - SPLessons
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. Syntax
<%=  statement %>

shape Example

Following is the best and simple example for JSP Expression Tag to printing the username using the expression tag. exptag.jsp [java] <html> <body> <form action="welcomeexp.jsp"> <input type="text" name="uname"></br> <input type="submit" value="go"> </form> </body> </html> [/java] Here the developer just created text box to enter the user name and also created the submit button that is go. welcomeexp.jsp [java] <html> <body> <%= "Welcome to "+request.getParameter("uname") %> </body> </html> [/java] The request.getParameter() method is used to retrieve the data. Output 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.

Summary

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.