In JSP, java code can also be written inside the jsp page by making use of the scriptlet tag. Firstly, let's check what are scripting elements.
The scripting elements give the capability to insert java code inside the jsp. Scripting elements are of three types that are:
For executing the Java source code in JSP a scriptlet tag is used. The syntax is given below:
<% java source code %>
We are going to present a welcome message in the below given example:
<html> <body> <% out.print("welcome to jsp"); %> </body> </html>
We have generated two files in this example that are index.html and welcome.jsp. The index.html file acquires 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="go"><br/> </form> </body> </html>
<html> <body> <% String name=request.getParameter("uname"); out.print("welcome "+name); %> </form> </body> </html>