• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

c:if statement failing every single time

 
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a very simple JEE project that I am building in Eclipse using Maven. Three text boxes and a submit button which validates the entries and redirects to a second JSP page if successful.

This code checks the request parameters from the submit button:


The problem is that the c:if fails and I cannot figure out why. I am using source code taken straight from my textbook.

This is the code for the web form, located in the same JSP file:


All the required bean classes and variables and dependencies have been declared etc. as per the textbook instructions. I just need to figure out why it won't register the POST request from the submit button.

I set a breakpoint on the conditional statement in question and attempted to debug it. At the line, I select Step Over and get the message, "addCourse.jsp line: not available". This occurs three more times and then the test terminates at the end of the c:if statement, skipping the entire nested block.

Any ideas why this might be happening?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty sure it's because <c:if test="..."> expects to be given an EL expression, and you appear to have given it some Java code instead. You might find that the EL expression you're looking for is actually simpler than that Java code, since EL gives you direct access to form parameters and other such things.
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul has correctly pointed out that you are using java code in an EL expression.
This may or may not work depending on your environment
What server are you running this on?


My suggestion would be to print out the values on the page so you can see what they evaluate to:


However there is a fundamental flaw in this JSP.
JSP is the "view" layer of MVC, and should only be used as such.
It should not do any processing/logic in reaction to a response. (in this case seeing that the submit button was pressed)

That responsibility should be in a servlet - in full on Java code.
Keep business logic out of your JSPs. It's just better that way.

 
Christopher Button
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your replies. However, I figured out the issue: My EL hadn't been activated; it had nothing to do with JSTL as such.

I added the following to the top of my JSP:

I'm a bit annoyed at having to do this. Is it common to have to add this specific declaration to get EL to work?

I've heard it has to do with the web.xml making use of Servlet 2.3 instead of 2.4, so I'll look into that as well. As it stands, my automatically generated web.xml looks like this:


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christopher Button wrote:I'm a bit annoyed at having to do this. Is it common to have to add this specific declaration to get EL to work?


No. Your web.xml is not configured correctly. You are using a DOCTYPE, you need to be using XML Schema. See the JspFaq for more information.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Stefan is correct; this functionality should not be in a JSP.
 
Christopher Button
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Bear. I consulted the relevant FAQ article and did some further reading and indeed, it should be declared as an XML schema. The DOCTYPE declaration appears to have been the default for the pre-Tomcat 6 era, so I haven't the foggiest as to why Maven generated a much older web.xml, especially puzzling given that I'm using the latest version of Eclipse, which in turn contains the most recent version of Maven.

As to the choice of design pattern, I can certainly see why this approach is not ideal, however I am simply following the instructions and steps outlined in my beginner's manual. Improvement in this particular area will no doubt increase with my experience.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right -- many beginner tutorials even start off putting Java code in a JSP :shock: . Just be aware that at the professional level it is considered bad form to use a JSP as anything other than a view.
 
Christopher Button
Greenhorn
Posts: 14
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately, it looks like I'm going to have to go back to the old DTD; it's the only way I can get my application to compile. After considerable time trying to get it to work with an XSD format, every time I change to XSD, I get the JasperException mentioned here:

https://coderanch.com/t/661310/Web-Services/java/JasperException-absolute-uri-resolved#3069752

Extensive reading throughout the internet has yielded no clear answer at all, despite the error being fairly common.
 
Christopher Button
Greenhorn
Posts: 14
1
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pardon the double post, but the gods have taken pity on me and provided me, at last, after several gray hairs, with the solution, posted here:

https://coderanch.com/forums/posts/list/661310#3070090
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic