In this JSP tutorial, you will learn about two types of Directive tag namely Include and Tag Lib and also Scriptlet tag used in Java Server Pages along with syntax, usage, example and explanation for each of the tag.
There are three types of scripting elements:
It is the main scripting element of JSP. It is the main tag of JSP page that is used to define _jspService( ) method of Auto Generated Servlet i.e. contents of Scriptlets are placed in _jspService( ) method at the time of translation. All the statements which are placed within scriptlets are moved to _jspservice( ) method in the Auto Generated servlet at the time of translation
<% java source code %>
In this example, we are displaying a welcome message.
<html> <body> <% out.print("welcome to JavaTportal"); %> </body> </html>
we have created two files index.html and welcome.jsp. The index.html file gets the username from the user and the welcome.jsp file prints the username with the welcome message.
<html> <body> <form action="welcome.jsp"> <input type="text" name="uname"> <input type="submit" value="Login"><br/> </form> </body> </html>
<html> <body> <% String name=request.getParameter("uname"); out.print("welcome "+name); %> </form> </body> </html>