Open In App

JSP | ScriptletTag

Java Server Page (JSP) is a technology for controlling the content or appearance of Web pages through the use of servlets. Small programs that are specified in the Web page and run on the Web server to modify the Web page before it is sent to the user who requested it. There are total three Scripting Element in JSP

  1. Scriptlet tag
  2. Expression tag
  3. Declaration tag

Using these tags we can insert our java code in JSP.



Scriptlet tag

This tag allow user to insert java code in JSP. The statement which is written will be moved to jspservice() using JSP container while generating servlet from JSP. When client make a request, JSP service method is invoked and after that the content which is written inside the scriptlet tag executes. 






<html
<body
<% out.print("GeeksforGeeks"); %>  <!-- scriptlet tag -->
</body
</html>

Explanation

Here we are creating and HTML file to take username from user.save this file as index.html. 




<!--index.html  -->
<!-- Example of JSP code which prints the Username  -->
<html
<body
<form action="Geeks.jsp">
<!-- move the control to Geeks.jsp when Submit button is click -->
 
Enter Username:
<input type="text" name="username"> 
<input type="submit" value="Submit"><br/> 
 
</form
</body
</html

Here we are creating A jsp file names as Geeks.jsp 




<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html>
 
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>Insert title here</title>
</head>
 
<body>
<% 
String name=request.getParameter("username"); 
out.print("Hello "+name); 
%> 
</body>
 
</html>

output


Article Tags :
Uncategorized