What is difference between scriptlet and expression

Showing Answers 1 - 6 of 6 Answers

Bhagavan Chowdary .A

  • Jun 13th, 2005
 

With expressions in JSP, the results of evaluating the expression are converted to a string and directly included within the output page. Typically expressions are used to display simple values of variables or return values by invoking a bean's getter methods. JSP expressions begin within <%= ... %> tags and do not include semicolons: 
But scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables or methods to use later in the file, write expressions valid in the page scripting language, use any of the JSP implicit objects or any object declared with a .

soma

  • Jul 25th, 2005
 

When U explain difference between a scriptlet and the expression the understanding will be bettere if u give examples of each also

  Was this answer useful?  Yes

PChal

  • Aug 11th, 2005
 

Anything that is put in the Jsp Expression tag get evaluated to a string, which, technically becomes an argument to the println() statement in the generated servlet.( JSP eventually is converted to a servlet ) otherwise it serves no purpose on its own. 
 
Expression has the following syntax 
 
<%= obj.getXXX() %> NO SEMICOLON 
 
Scriptlet: <% Any java code can go here. What ever is put here will go into the service method of the generated Servlet. 
 
Variables declared here will become local variables 
 
%> 

  Was this answer useful?  Yes

veena

  • Aug 26th, 2005
 

scriplets syntax is<% %>and expressions syntax is<%=expression%>,which is written inside scriptlet,for displaying the values which is extracted from client side

  Was this answer useful?  Yes

madhavi

  • Oct 1st, 2005
 

An Expression tag opens with <%= and ends with %>

Scriptlet tag opens with <% and ends with %>

ex:

<%! int a=10,b=5,res=0;%>

<%res=a+b;

out.print("Result is "+res); %>

<html><body><p>

The Result is <%=a+b%></p></body></html>

An Expression tag is used to evaluate an expression and assigns its value but scriptlet tag is for simply java code that may be any statements like expression,display statements etc. 

  Was this answer useful?  Yes

siva kumar reddy

  • Aug 1st, 2006
 

 scriptelet are used to write the code in any language but that language is mentioned in page language attribute.

ex:<% System.out.println("im siva kuma "); %>//returns siva kumar

expession are used to display the simple values and returning values.

ex:

<%! public String getName(){

   return "siva kumar";

} %>  //jsp exression

whenever we want to get the value of that method we have to use folowing expression

< %=getName(); %>//it returns siva kumar

cheers

siva kumar reddy

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions