Sunday, 27 August 2017

JSP Scriptlet tag (Scripting elements)

JSP Scripting elements


The scripting elements provides the ability to insert java code inside the jsp. There are three types of scripting elements:
  • scriptlet tag
  • expression tag
  • declaration tag

JSP scriptlet tag

A scriptlet tag is used to execute java source code in JSP. Syntax is as follows:

<% java source code %> 
 
Example of JSP scriptlet tag

<html>
<body>
<% out.print("welcome to jsp"); %>
</body>
</html>

Example of JSP scriptlet tag that prints the user name
In this example, 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.

File: index.html
<html>
<body>
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>
</body>
</html>

File: welcome.jsp
<html>
<body>
<%
String name=request.getParameter("uname");
out.print("welcome "+name);
%>
</form>
</body>
</html>

Post a Comment

Whatsapp Button works on Mobile Device only

Start typing and press Enter to search