• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scripting varibale unavailable in EL expression

 
Vishal Chugh
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We cant use scripting varibale in EL .

Then i think reason being:
All scriptlet code lands inside_jspService() method directly , if some varibale is placed in scriplet , then it wont be accesible in EL .

Is my understanding correct?? Please guide


[ December 28, 2008: Message edited by: Vishal Chugh ]
 
Baddy Davay
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think during transition phase from JSP to JAVA class, When the container finds <% %> tags , It just copies it to the java class file,But other parts of the jsp are handled differently,In the sense they are transformed in to java code and then written in the java file.
 
Santosh Raveendran
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishal

why should we use scripting varibale in EL? , any code that is not part of a declaration(<%! %> will definetly go inside the _jspService()
[ December 31, 2008: Message edited by: santosh raveendran ]
 
Vishal Chugh
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FIRST OF ALL, A VERY HAPPY AND PROSPEROUS YEAR-09 TO YOU ALL .....

We hope 2009 will be free from terrorism and market slump.


Hi,

I had below code in enthuware mock :

<select name="Cities">
<%for(int i=0; i<cities.size(); i++) {%>
<option>${cities[i]}</option>
<%}%>
</select><br>

Here cities was not accessible in for body , i missed it , so posted may be use for others.

Thanks a lot for response...
Vishal Chugh
 
Phillipe Eduardo Lemos
Greenhorn
Posts: 7
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The answer for this question is scope. In EL API the VariavelResolver object search for name in pagecontext scope, request scope, session scope, application scope and returns the first ocurrence
(See JSP specification 2.0 pag. 1-75 session 2.5 - http://jcp.org/aboutJava/communityprocess/final/jsr152/index.html). The scope of scriptlet code is local to _jspService. But if
you put the scripting variable in some of scope where EL look for then it's work. Try the follow code

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String[] cities = {"Rio de Janeiro", "New York", "London","Japan"};
pageContext.setAttribute("cities", cities);
%>
<select id="Cidades" name="cidades"
<c:forEach begin="0" end="3" var="i">
<option>
${cities[i]}
</option>
</c:forEach>
</select>
<br>
</body>
</html>
 
liao Yang
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EL is about using attributes and implicit objects. It has no access to local variables.

Hope this helps.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic