JSTL not recognized in JSP after adding jar - java

I added jstl-1.2.jar to my lib folder, then I included:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
on top of my JSP file and still It says `Unknown tag (c:forEach).
welcome.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:forEach>
</c:forEach>
</body>
</html>
Project construction HERE

1.Use only jstl-1.2.jar
2.Try to get some items to iterate, for example:
<c:forEach items="${requestScope.list}" var="item">
</c:forEach>

Related

contextPath is empty in JSP page while using it with Spring Boot

I want to load CSS on the JSP page. But I am getting empty pageContext.request.contextPath in JSP page. I am using this approach because if I move the page around in different directories within the templates or JSP then I should not need to keep on making changes to paths of referred CSS or js files.
Jsp page is as below
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%# taglib prefix = "x" uri = "http://java.sun.com/jsp/jstl/xml" %>
<%# taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
<%# taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions" %>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%#page isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Home Page</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/default-theme.css" />
</head>
<body>
<div class="container">
<H2>Reached Home.</H2>
</div>
</body>
</html>
application.properties file is as below
spring.mvc.view.prefix=/templates/jsp/
spring.mvc.view.suffix=.jsp
I am using Spring version 2.6.0. Along with the following dependencies in pom.xml-
spring-boot-starter-web
spring-boot-starter-tomcat (scope: provided)
tomcat-embed-jasper (scope: provided)
jstl
As per Spring Boot, pageContext is Implicit. Then what could be going wrong here?
Any help or suggestions would be appriciated.
check if remove <%#page isELIgnored="false"%>
if not work test : request.getContextPath()
after all see this link :
pageContext.request.contextPath not working

<sec:authorize does not work in some jsp pages

I want to show the Authenticated user's firstname and lastname. I put related code segment in Header.jsp and include it in two other jsp pages, Index.jsp and News.jsp.
When Header.jsp included in News.jsp, it works correctly and displays Authenticated user's firstname and lastname, but when it's include in Index.jspm it doesn’t show anything.
My pages structure looks like blow:
Header.jsp
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%# taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="usertext">
<span id="loginedUserFullname">
<sec:authorize access="isAuthenticated()">
<sec:authentication property="principal.firstname" />
<sec:authentication property="principal.lastname" />
<span class="welcome">welcome</span>
<a class="logout" href='/view/cpanel/Logout.jsp'>(loge out)</a>
</sec:authorize>
</span>
</div>
</nav>
Index.jsp
<%# page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="">
<meta name="description" content="">
<jsp:include page="/includes/front/Head.jsp"></jsp:include>
<title></title>
</head>
<body>
<jsp:include page="/includes/front/Header.jsp"></jsp:include>
<jsp:include page="/includes/front/Scripts.jsp"></jsp:include>
</body>
News.jsp
<%# page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="">
<meta name="description" content="">
<jsp:include page="/includes/front/Head.jsp"></jsp:include>
<title></title>
</head>
<body>
<jsp:include page="/includes/front/Header.jsp"></jsp:include>
<jsp:include page="/includes/front/Scripts.jsp"></jsp:include>
</body>
whats wrong with <sec> that doesn't work in the Index.jsp?
Is it possible that Index.jsp does not require the user the be authenticated but News.jsp does?

Warning in an Anchor Tag in a JSP File

I am able see the warning in a jsp file for the anchor tag.
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page import="java.util.Date" %>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Bills Added</title>
</head>
<body>
<h1>Bills Added</h1>
<p>You have added a new bill at</p>
<c:url var="mainUrl" value="/bills/add" />
<p>Return to Main List</p>
</body>
</html>
In the line <p>Return to Main List</p> its showing a warning:
WebContent/WEB-INF/jsp/${mainUrl} not found.
I can understand about the c:url tag but in the href with the place holder ${mainUrl}, then its showing warning in all the files which I have placed like this format. Please neeed suggestion to fix this or why am getting this?

<c:foreach> jstl tag doesn't print anything

The tag doesn't work... Jsp doesn't print anything... Could I debug jsp page in Eclipse?
view
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<ul>
<c:forEach items="${listOfMyFriends}" var="friend">
<c:out value="${friend}"></c:out>
</c:forEach>
</ul>
</body>
</html>
controller are in MyController.java
#Controller
public class MyController {
#RequestMapping(value="/my")
public String getMyHomePage(Model model) {
LinkedList<String> listOfMyFriends = new LinkedList<String>();
listOfMyFriends.add("friend1");
listOfMyFriends.add("friend2");
listOfMyFriends.add("friend3");
listOfMyFriends.add("friend4");
model.addAllAttributes(listOfMyFriends);
return "my";
}
}
Replace the line before the return with
model.addAttribute("listOfMyFriends", listOfMyFriends);
When you do a model.addAllAttributes(listOfMyFriends);
It Copies all attributes in the supplied Collection into this Map, using attribute name generation for each element.
Attribute name generation is done using the method : Conventions.getVariableName()
So, if you are not certain what will be the generated attribute name, use
model.addAttribute("listOfMyFriends", listOfMyFriends);
So that you can access the list of your friends using the key "listOfMyFriends"
Add listOfMyFriends to the Model as follows :
model.addObject("listOfMyFriends ", listOfMyFriends );

calendar with struts 2

I currently work with struts2 and I need to display a calendar
in my jsp page and retrieve the date in yyyy-MM-dd
I try with this code
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<%# taglib prefix="sx" uri="/struts-dojo-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<sx:head cache="false" compressed="false" />
</head>
<body>
<sx:datetimepicker name="date achat" label="Format (yyyy-MM-dd)" displayFormat="yyyy-MM-dd"/>
</body>
</HTML>
but while running the schedule does not appear
and just this label is displayed
Format (yyyy-MM-dd):
best regards
franco
Try the following example
Struts2 DateTimePicker

Categories