12

I want to write a simple web page in .jsp file. I need to use <c:if> tag. but it is not recognized. eclipse said it is unknown tag.

I googled it and some said I need to include the standard lib (which is JSTL?).

I just want to use some basic tags in jsp file such as <c:if>. Do I really need to include any libraries? If so, what libraries do I need to include? And how to do that in Eclipse? Please let me know step by step about how to import/include these libraries or build path so that I can use <c:if> in my jsp file.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Joey
  • 2,732
  • 11
  • 43
  • 63
  • after some more research, I think I should put this <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> on the top of my file so that I can use tag. right? not sure yet. I think there is something more I have to do such as build path. – Joey Jul 12 '12 at 21:31
  • What server are you using? Most servers will automatically include jstl jars in the classpath – Victor Mar 22 '13 at 17:17

4 Answers4

17

Make sure that you have a taglib declaration in your JSP file

<%@ taglib
    prefix="c"
    uri="http://java.sun.com/jsp/jstl/core" 
%>

Also, make sure that you've added JSTL jar files to your project classpath.

Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
  • 1
    how to make sure I have JSTL jar files to my project, and if not, how to add it? I am sorry maybe this is a stupid question. I just have no idea how to do it – Joey Jul 12 '12 at 21:33
  • 2
    @user1387727 Here is how to add Jars to build path: http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29 – Alexander Pogrebnyak Jul 12 '12 at 21:40
  • @user1387727 And here is where to get them: http://stackoverflow.com/questions/292914/where-can-i-download-jstl-jar – Alexander Pogrebnyak Jul 12 '12 at 21:41
5
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<HTML>
 <HEAD><TITLE>JSTL 'if' tag</TITLE></HEAD>
 <BODY>
  <c:if test="true">Hello world!</c:if>
 </BODY>
</HTML>

Source: http://www.java2s.com/Code/Java/JSTL/JSTLiftag.htm

Eduardo Andrade
  • 946
  • 7
  • 10
  • I just found it and tested it. eclipse still said it is unknown tag. . – Joey Jul 12 '12 at 21:32
  • While your example is good, your HTML code doesn't follow the actual standard. Instead of just copy/pasting, show more effort and edit the answer. – Luiggi Mendoza Jul 12 '12 at 21:42
1

You need to see this link JSTL tag library to select the right libraries version and its header:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

or

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
Community
  • 1
  • 1
John Alexander Betts
  • 4,718
  • 8
  • 47
  • 72
0

add this tag..

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

and copy this two jar file in your project folder web-inf->lib

javax.servlet.jsp.jstl-1.2.1.jar javax.servlet.jsp.jstl-api-1.2.1.jar

RamChithra
  • 57
  • 2
  • 10