Scripting elements is used to insert java
code inside the jsp. There are three types of scripting elements, they are
Example 2(taking value from user)
Note: Do not end your statement with semicolon in
case of expression tag
- scriptlet
tag
- expression
tag
- declaration
tag
Scriptlet tag
Scriptlet tag is used to execute java source
code in JSP
Syntax:
<% java source code %>
Example
1:
<<html>
<body>
<% out.print("welcome to
Learningpoint92"); %>
</body>
</html>
Example 2(taking value from user)
Index.html
<html>
<body>
<form
action="demo.jsp">
<input
type="text" name="t1">
<input
type="submit" value="display"><br/>
</form>
</body>
</html>
demo.jsp
<html>
<body>
<%
String name=request.getParameter("t1");
out.print("Heyy"+name);
%>
</form>
</body>
</html>
Expression tag
It is used to print the values of variable or
method.
Syntax:
<%= statement %>
Example 1:
demo.jsp
<html>
<body>
<%= "welcome to Learningpoint92" %>
</body>
</html>
Example 2(taking value from user)
Index.html
<html>
<body>
<body>
<form action="demo.jsp">
<input type="text" name="t1">
<input type="submit" value="display"><br/>
</form>
</body>
</html>
demo.jsp
<html>
<body>
<%= "Heyy "+request.getParameter("t1") %>
</body>
</body>
</html>
Declaration tag:
declaration tag is used to declare fields and methods.
Syntax:
<%! field or method declaration %>
Example 1:
demo.jsp
<html>
<body>
<%! int x=20;%>
<%= "Value of the x
is:"+x %>
</body>
</html>
Example 2:
demo.jsp
<html>
<body>
<%!
int add(int a,int
b){
return a+b;
}
%>
<%= "Addition
is:"+add(4,6) %>
</body>
</html>
Python is an open-source, high level, interpreted programming language which offers great opportunities for object-oriented programming. Choosing a python training program from Red Prism Group, which is best training institute for python in noida.
ReplyDelete