Syntax of JSP Scriptlet is:
<%
//your java code here
%>
A JSP Scriptlet begins with the sign <% and ends with the sign%>. Java code can be embedded in the JSP Scriptlet. JSP Engine places the code present in the scriptlet tag in the _jspService() method of the JSP page. Variables that are available to the JSP Scriptlet are:
- request:
request is used to represent the client's request and is a subclass of HttpServletRequest. This variable is used to retrieve the data which was submitted along the request.
Example:
<%
//java code
String name=null;
name=request.getParameter("user_name");
%> - response:
response is subclass of HttpServletResponse. This is used to send a response.Example:<% response.sendRedirect(“nextPage.jsp”);%> - session:
session represents the HTTP session object associated with the request.Example:<%session.getAttribute(“attribute_name”);%> - out:
out is an object of output stream and is used to send any output to the client.
Example:
<%out.println(“Hello World”);%>
This will print Hello World on the web page.
Other variables that are available to the scriptlet are pageContext, application,config and exception.
No comments:
Post a Comment
Please comment, if you like the post, you find any mistake or if you have any query.