Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Attribute with JSTL.Thanks!

 
Kidd He
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 JSTLTest.java 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>:
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

HTH,
Srikanth
[ November 24, 2006: Message edited by: Srikanth Raghavan ]
 
Kidd He
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic