This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes why doesn't this work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "why doesn Watch "why doesn New topic
Author

why doesn't this work?

Mitch Miller
Greenhorn

Joined: Mar 10, 2006
Posts: 13


Expression is blank, not "1".
Tomcat produced:
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${one}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));

Tomcat doc says:
public static java.lang.Object proprietaryEvaluate(java.lang.String expression, java.lang.Class expectedType, javax.servlet.jsp.PageContext pageContext, ProtectedFunctionMapper functionMap, boolean escape) throws javax.servlet.jsp.el.ELException

expectedType - The expected resulting type

if "expectedType" is String, shouldn't it produce "one.toString()"

Similarly: ${one + 1} = "1" not "2"
I expected Integer to be automatically converted to int primitive.

Thanks for your help,
Mitch


SCJP 1.4 80%
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Mitch Miller:
[QB]


EL should not mixed with scriplet.. if you want output try this




if you want to display an object using EL.that object should in any of the scope[something like request.setAttribute("one",one)..]
got it?

note: please discourage the scriptlet

Hope This Helps
Mitch Miller
Greenhorn

Joined: Mar 10, 2006
Posts: 13
Thank you.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

You are welcome
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
As seetharaman discouraged you from using scriptlet. Thanks, Seetharaman for a good advice.



This code should work. Its equivalent to what you were trying to achieve. This wouldn't bind the thing to request object, unlike the given scriptlet code.

Cheers.

[Edited]
Changed scope from request to page.
[ August 14, 2008: Message edited by: Adeel Ansari ]
Jan Sterk
Ranch Hand

Joined: Jun 06, 2008
Posts: 139
Originally posted by Adeel Ansari:



(...) This wouldn't bind the thing to request object, unlike the given scriptlet code.

Cheers.


Could you clarify on that? To my understanding, c:set does create an attribute for the given scope (request in this case) - just like the scriptlet does. Otherwise there's no way to get the value with EL.
[ August 14, 2008: Message edited by: Jan Sterk ]

SCJP 1.4 (81%)<br />SCWCD 5 (95%)
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Jan Sterk:

Could you clarify on that? To my understanding, c:set does create an attribute for the given scope (request in this case) - just like the scriptlet does. Otherwise there's no way to get the value with EL.



you are right JAN
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
The reason that the original code does not work is that the variable declared is a variable local to the Page but not in the PageContext scope.

The EL does not look at local Page variables.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Sorry did I post "request". I meant "page". So, the given code would become something like below,

Made correction to my original post. Thanks for pointing out Jan. I hope it became clear now.
[ August 14, 2008: Message edited by: Adeel Ansari ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why doesn't this work?
 
Similar Threads
JSP - UseBean
passing c:forEach value to custom tag as attribute?
Problems with jsp:useBean
EJB QL errors using ejbc
ServletException after JSP precompilation