• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL / EL / JSP Problems

 
Graeme Woodhouse
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I've just setup a Struts 1 web application (From the example blank application).

For right now i'm simply trying to have a action go to Java Class, set a request attribute, return the user to a response page which uses the core (<c tags to do a couple of conditional statements.

I've followed the JavaRanch FAQ's, downloaded JSTL 1.1, JSP 2.0 jar files and added them to my build path. I'm using the jsp-api.jar & servlet-api.jar file from tomcat/common/lib directory (I'm running this in Tomcat 5.5 with a java 1.6 compiler).

In the web application web.xml i have defined this:

web.xml (fragment)

My Action (fragment)

.JSP page (fragment)


The output it gives is here:

Can someone help me figure out why:

a) <cut value="${request.getAttribute('Step1')}"/> errors because of "(" character being used - runtime exception
b)<cut value="${request.getAttribute('Step1')}"/> in eclipse tells me ApplicationHttpRequest doesn't contain a getAttribute() method (This error made me redownload and extract my Tomcat instance - no change)
c) ${request.getAttribute("Step1") } is being output rather than interpreted.
d) Because of above the <c:when> is being evaluated as false?



Thank you very much!

Graeme
 
Graeme Woodhouse
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I also tried adding this: <c:set var="request" value="${pageContext.request}"/> before any calls to request which didn't work)
 
dileep keely
Ranch Hand
Posts: 108
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that you have the if condition get executed.

Can you try
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things to clean up:
  • Remove the taglib element from the web.xml. It's unnecessary and likely just gooping things up.
  • The URI you are using is for JSTL 1.0. Use the correct URI for JSTL 1.1/1.2.


  • That might just unclog things enough to get things working once you clean up the syntax. if not, at least all the incorrect goo will be out of the way.

    As pointed out "request.getAttribute" in the EL is not correct. Correct syntax is to just reference the scoped variable name.
     
    Graeme Woodhouse
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you Dileep, that fixes the problem of my <c:when> tags not working.

    Bear, which URI is JSTL 1.0 ?

    I removed the web.xml definition and it does indeed work fine without it. Is defining the URI in the web.xml depreceated?

    Both of you advice really helped so far thank you!
     
    dileep keely
    Ranch Hand
    Posts: 108
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I've followed the JavaRanch FAQ's, downloaded JSTL 1.1,

    Bear was referring JSTL 1.0 --> uri="http://java.sun.com/jstl/core"
    instead the suggestion was to use http://java.sun.com/jsp/jstl/core for JSTL 1.1
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65519
    105
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Graeme Woodhouse wrote:Bear, which URI is JSTL 1.0 ?

    The one you are using is JSTL 1.0. Do you not have the JSTL 1.2 Specification open on your desk? It should be.

    I removed the web.xml definition and it does indeed work fine without it. Is defining the URI in the web.xml depreceated?

    It is only necessary when the taglib's jar file is not properly formed according to modern standards.
     
    Graeme Woodhouse
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Downloaded the specification (Well hidden now that Oracle are in charge) and changed the URI for the core taglib definition.

    Thanks again Bear & Dileep!
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65519
    105
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You're welcome.

    Graeme Woodhouse wrote:Downloaded the specification (Well hidden now that Oracle are in charge)


    Don't blame Oracle -- Sun's sites have always been a paragon of obfuscation.
     
    Graeme Woodhouse
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm afraid this problem has inexplicably come back. I've been working on code in the action and CSS on the page - nothing architectural so no idea which change has broken it. I've reverted the page to simply the below:


    is giving the output:
    ${requestScope.Step1} ${Step1} ${Step1} true

    I'm stumped again - why is this giving me so much trouble?! You can see from the servlet the attribute is set, the core taglibs are working fine but the EL is simply refusing to work.
     
    Graeme Woodhouse
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Adding <%@ page isELIgnored ="false" %> to the page fixes the problem...

    Seeing as how the specification to ignore EL is turned off i'm not sure why Tomcat is insiting that EL should be ignored by default.

    Some Expression Language Documentation
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!