This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Servlets 4a - problems using Expression Language in listvideos.jsp  RSS feed

 
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get my head around this assignment, and while taking my first tentative steps I've noticed that I can't seem to use EL in the JSP to read attributes I wrote to the ServletData object in the ActionHandler.  It just displays the EL tag as literal text.

Looking at the provided bee example (which works fine), it doesn't use EL, but embedded Java code.  And swapping between the 2 approaches on both JSPs gives me the same results, embedded code works fine in listvideos.jsp as well, and EL just displays the tag in bee.jsp.  But that doesn't solve my problem because the instructions for 4a say to use EL (and JSTL, which I haven't gotten round to using yet) to build the table displaying the data.

Am I missing something about EL within the Front Controller pattern?  I've tried setting the attribute the ServletData object's underlying HttpServletRequest object using:

servletData.getRequest().setAttribute( "testMessage", "text to display in the JSP." );

but it behaves the same, only displaying properly when I use embedded Java.

Any pointers would be greatly appreciated!

 
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

You're right that the Bee MVC example in the instructions uses embedded Java, but only because it comes right before the introduction of EL. Once you know EL, you should never use embedded Java ever again.

Currently it's:



With EL, it would be:

It's easier to write and it's easier to read. Win-win! Anyway, see if that works for you. If not, maybe we'll have to look at versions of things that you're using. EL has been around for quite a long time now though, so I'd be surprised if that's it.
 
John Godfrey
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Greg - unfortunately, I tried the jsp you posted and I get the same result, the browser simply displays the EL as written (so in this case, "${text}").

When I run the most recent assignment I did using EL (reverse2), it works as expected, so I wondered if it had anything to do with using ActionServlet, as that's the obvious difference between the working and non-working uses of EL.  However, I tested this by changing the implementation of VideoServlet so that it extended only HttpServlet as before, and I still couldn't get EL working.  I even went so far as to copy the working code from Reverse2Servlet.java into VideoServlet.java and the html from reverse.jsp into listvideos.jsp (changing only the necessary parts like the class name, and targets of the RequestDispatcher and action) and still the same result - everywhere I use EL, it just prints the expression literally.

So, could it be some kind of setting I've inadvertently changed for this webapp in Tomcat, or in the Ant script maybe?  I tried remaking my Ant script, but it hasn't made a difference - is there something I can check in the Tomcat manager app perhaps?  But then, I have the same problem with bee, so was there something I did differently for reverse2?

Really confused now!  I'd really appreciate any pointers.
 
John Godfrey
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I worked it out! This webapp's web.xml was declaring that it conformed to an older version of JSP (I think I may have copy/pasted it from an example I found on the web when I was looking at other examples).  As soon as I changed it to the version specified in the example in the Tomcat instructions Greg sent, EL worked again as before.

So you were right Greg, it was a version problem.  Thanks for the pointer!

Now back to the assignment - I imagine there'll be more questions to come . . .
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! I'm glad you got that working!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!