JSP expression - some java expression usually object, boolean, math calculation , conversion
EXAMPLES
1) <%= new java.util.Date() %>
2) <%= new String("hello to uppercase").toUpperCase() %>
3) <%= 24*4 %>
4) <%= 75<8 %>
5) <% String lName = "Bledar Ramo"; %> <%= lName%>
JSP scriptlet some java code 1-to many lines ,Executable java code or we can use out.println
EXAMPLES
1)
<%
for(int i=0;i<10;i++){
out.println("loop same message"+i);
}
%>
2)
<% String localstring ="JSP scriptlet";%>
<% String string2 ="Bledar Ramo";%>
<% if(localstring.equals("JSP scriptlet"))
out.println("Hi"+string2);
else
out.println("hello ghost");
%>
3)
<% out.println( request.getRemoteHost()); %>
4)
<% int count = 0; %>
Count is <% out.println(++count); %>
5)
<form method="post" action="index.jsp">
Name <input type="text" name="user" >
<input type="submit" value="submit">
</form>
<% String user = request.getParameter("user"); %>
<% out.println(user); %>
JSP declaration decalre variables, method , members ,instances
EXAMPLES
1)
<%! String name="Chaitanya"; %>
<%! int age=27; %>
<%= "Name is: "+ name %><br>
<%= "AGE: "+ age %>
2)
<%!
String makeitLower( String data){
return data.toLowerCase();
}
%>
<%= makeitLower("HELLO WORLD") %>
3)
<%!
int sum(int num1, int num2, int num3){
return num1+num2+num3;
}
%>
<%= "Result is: " + sum(10,40,50) %>
4)
<%! int fontS; %>
<% while ( fontS <= 10){ %>
<font color="red" size="<%= fontS %>">
Ramo code
</font><br />
<%fontS++;%>
<%}%>
5)
<%! int imgSize; %>
<%for ( imgSize = 10; imgSize <= 30; imgSize++){ %>
<img src="http://www.w3schools.com/tags/smiley.gif" alt="Smiley face" height="<%= imgSize %>" width="<%= imgSize %>">
<%}%>
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.