Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

<c:out> is not working properly

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Head First Servlets and JSP to prepare for SCWCD.

In the book there is code using<c:out> tag which is not working. I have places the jstl.jar and standard.jsr file in WEB-INF/lib directory.

It is not displaying the currentTip

I will just reproduce the code here.

servlet code:


The tip.jsp code


The out put is:
Tip of the day is

It is not diaplying the currentTip? I don't understand what seems to be the problem. I have done everything axactly as told in the book. I am stuck at this an unable to move ahead. And this is stalled my prepaeration. Please help me solve this problem.

regards
Anil Deshpande
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using pageContext instead of pageContent.
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Did you specify taglib for what c is ?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand where is pageContect object from? There is pageContext object but not pageContent - as far as I know.
Try just .
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Your are using the Expression Lang, in order to use E.L in your page you should enable it by default it is disabled.
<%@ isELIgnored="false" %>
put this code hope so it works.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Your are using the Expression Lang, in order to use E.L in your page you should enable it by default it is disabled.


No, it is enabled by default, at least since JSP2.0. Don't use the isELIgnored attribute.
Also, it is an attribute of the page directive. Your notation would not work.
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the book it is printed as pageContent. It is not working. i don't know whether it is printing mistake or something else. Just to cross check I changed it to pageContext.currentTip, It gave an exception. The exact details of the exception are as follows.



Then I even chaned it to cust currentTip, It doesn't make any difference. Even though exception is not thrown, nut stull it doesn't sisplay anything. What seems to be problem?


Did you specify taglib for what c is ?



What does that mean, and how to do it. I have placed the JSTL jar files in the WEB-INF/lib directory.If that's what you mean
 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>

Do you have it in your JSP?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, like Cezary said ... try this

Cezary Rzewuski wrote:I don't understand where is pageContect object from? There is pageContext object but not pageContent - as far as I know.
Try just .



EL will check all available scopes searching for an attribute bound with the name "currentTip"

you can also do it like this


I wonder how you got the exception, since EL is null friendly .... very weird!
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>


(In the Head first book nothing about that is mentioned, that's why I didn't know it)

Well I didn't know that. I did include that in the jsp. It seems to to be moving somewhere ahead. Thre seems to be some minute problem.

Now its giving another exception in jsp.



What shall I do?



I wonder how you got the exception, since EL is null friendly .... very weird!

That's what I too am unable to understand
regards

Anil Deshpande
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
is the correct syntax for describing custom libraries in jsp. there was an extra semicolon in above post.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In any case, this definition is old. You should be using this one :


Check this page.
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>




This tag is working perfectly fine. But I changed pageContent.currentTip to just currentTip, or requestScope.currentTip. I personally feel there is no EL having pageContent. and anyhow pageContext is throwing the exception.

The code is working fine now. Thanks a lot guys. I really appreciate all the replyes.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. There is no pageContent implicit object in EL
2. There is a pageContext implicit object in EL, whose type is javax.servlet.jsp.PageContext. This class has no method called "getCurrentTip", which causes the exception.
3. The "currentTip" attribute is set in the request, so as Mateus said, you can either use the requestScope implict object to get it (${requestScope.currentTip}), or let the container look for it by using ${currentTip} instead.

That should be added to the errata of the book, if it's not already there.
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic