• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<c:out> is not working properly

 
Anil Deshpande
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<cut> 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
 
Dumitru Postoronca
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using pageContext instead of pageContent.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Did you specify taglib for what c is ?
 
Cezary Rzewuski
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 .
 
chandraiah chintakayalu
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 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
 
Harshana Dias
Ranch Hand
Posts: 348
  • 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?
 
Mateus Lucio
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
 
vani venkat
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 Ubuntu VI Editor
  • 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 Ubuntu VI Editor
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic