• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

JSTL instead of scriplets



Dear experts

I have this scriplet in my jsp page

<%
  if(request.getAttribute("result") != null) out.println((String)request.getAttribute("result"));
%>

and "result" is a bytestream which prints on the screen AND "result" is set in request scope.

Is there any way i can use JSTL tags and use something like c:if to do the same functionality.
Basically i want to avoid scriplets in my jsp page

thanks
J
0
jaggernat
Asked:
jaggernat
  • 5
  • 4
  • 3
  • +2
2 Solutions
 
rrzCommented:
<c:if test="${result != null}">
           ${result}
</c:if>
or if you are not using JSP 2 then use
<c:if test="${result != null}">
           <%=request.getAttribute("result")%>
</c:if>
0
 
boonlengCommented:

<c:if test="${not empty requestScope.result}">
    <c:out value="${requestScope.result}"/>
</c:if>
0
 
suprapto45Commented:
Another way is to use <c:choose></c:choose> combination.

No point for me please :) cause rrz and boonleng has provided you the correct answer.

David
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jaggernatAuthor Commented:
>>><c:choose></c:choose>

yeah, i guess   c:choose  is used when doing if-elseif-elseif...

0
 
evnafetsCommented:
You could just use: <c:out value="${requestScope.result}"/>
If it is the request attribute "result", it won't print out anything.
0
 
rrzCommented:
Good point, evnafets. So, just    ${result}    for JSP 2 would work as well.
0
 
jaggernatAuthor Commented:
thanks for all the responses guys. One last problem. I dont have c.tld in my web-inf . i am assuming c.tld and put it in web-inf and  import in  my jsp like

      <%@taglib uri="/WEB-INF/c.tld" prefix="bean"%>  

any ideas how i can download c.tld for free.

thanks
0
 
jaggernatAuthor Commented:
>>>>>>i am assuming c.tld

I meant  i am assuming c.tld should be downloaded and put in web-inf
0
 
evnafetsCommented:
No you should not have c.tld in your WEB-INF, or indeed anywhere in your web application or web.xml.
It is already present in "standard.jar" in the WEB-INF/lib directory.

As long as you use the standard uri to import the tag, it should work with only the jar files present:
The standard import line for JSTL1.1:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
0
 
rrzCommented:
>I meant  i am assuming c.tld should be downloaded and put in web-inf    
No.  Please follow the following steps.
Go to   http://jakarta.apache.org/site/downloads/downloads_taglibs-standard.cgi   
Click on 1.1.2.zip which will download  jakarta-taglibs-standard-1.1.2.zip to you  ( I assume you are on windows)(It is free).
Unzip it. Inside you will find a lib folder and inside that you will find two jars  standard.jar and jstl.jar. Put these two jars into <yourTomcatHome>\common\lib  .(I assume you are using Tomcat 5)   In your JSPs put the following line.  
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
Now use the code I posted.   You don't have to worry about the tld because it's in the jars.
0
 
rrzCommented:
Sorry evnafets, I didn't see your post.
0
 
jaggernatAuthor Commented:
>>>>>Put these two jars into <yourTomcatHome>\common\lib  .(I assume you are using Tomcat 5)  

hi,
 i am using Jbuilder 2005 with Weblogic application server. So where do  i put the two jar files?

thanks
0
 
rrzCommented:
Sorry, I only use Tomcat.
0
 
evnafetsCommented:
You should put the jar files in the WEB-INF/lib directory of your web application.
That will work on any server.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now