File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt in Attribute with JSTL.Thanks! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt in Attribute with JSTL.Thanks!" Watch "Doubt in Attribute with JSTL.Thanks!" New topic

Doubt in Attribute with JSTL.Thanks!

Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
I get the input from the form.html, and I want to see the JSTL.jsp include the include.jspf(at bottom) with a difference sentence.But why I always get all the four <c:if> sentence?I want to see only one. My opinion is because the request and response in are only passed to JSTL.jsp, the include.jspf haven't gotten them, but why it show all the four choices(I think there should be none)?
I will show a html,a Java code and a JSP with <jsp:include>,they are just for test:

The form.html:

The Java code:

And the JSTL.jsp is:

The include.jspf is, which has the problem with either <c:choose> or <c:if>:

SCJP1.4 93%<br />SCWCD��
Srikanth Raghavan
Ranch Hand

Joined: Oct 31, 2005
Posts: 389
Sorry but I think I didn't completely understand your question....

I will try and explain <c:if> and <c:choose> if that's what your question is...

<c:choose> and it's partners <c:when> and <c: otherwise> are not a replacement for multiple if statements... There are a way to have if, else if and else statements....

For example, the following Java code exactly relates to the JSP code after that...

Java Code:

JSP Code:

But what if you want to display something when it doesn't satisfy any of these two strings....

Java code:

But <c:if> can't be used to achieve this, so you have to use the <c:choose> tag....

JSP Code:

So, what I am trying to say is <c:if> and <c:choose> have different purposes and satisfies different needs...

[ November 24, 2006: Message edited by: Srikanth Raghavan ]
Kidd He
Ranch Hand

Joined: Sep 17, 2006
Posts: 65
Sorry,I should make it clearer:
When I submit a name in the form.html,I want to show the difference sentences in the include.jspf which will be imported in the JSTL.jsp.
For example,when I choose Kidd,it should only show the sentence "Now, this's Jason Kidd !" and others shouldn't appear.
But in fact when I choose any one among the four choices ,the include.jspf always show all the four sentences in the order,as if there aren't <c:if>s any more. When I use <c:choose> .it's all the same.
Why the <c:if> or <c:choose> didn't work,and furthermore based on the output they almost disappeared?
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Take a look at IncludesActionDirective from the JavaRanch JspFaq.

If you are showing your entire include.jsp I believe you need to either add the definition for the core taglib in that jsp (and name include.jsp rather than .jspf if it's going to be a jsp you can run) or alternatively use the include directive instead of the include action. The difference is whether it is code compiled into your JSTL.jsp or it's another jsp to execute and have the results of that execution included in the output page.
[ November 24, 2006: Message edited by: Carol Enderlin ]
I agree. Here's the link:
subject: Doubt in Attribute with JSTL.Thanks!
jQuery in Action, 3rd edition