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.