Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsp include not working

Tags:

java

html

jsp

i am trying to learn jsp, and when i include another .jsp file to my main page, its contents are not shown. here is the code

main.jsp

<html>
<head><title>the include action</title></head>
<body>
<center>
<h2>the include</h2>
<jsp:include page="/date.jsp"/ >
</center>
</body>
</html>

date.jsp

<p>
  Today's date: <%= (new java.util.Date()).toLocaleString()%>
</p>
like image 723
Rishabh Kapoor Avatar asked Jul 26 '26 10:07

Rishabh Kapoor


2 Answers

include like this

<jsp:include page="date.jsp"></jsp:include>

or use this at top of your jsp

<%@ include file="date.jsp" %>
like image 124
Ahmad Avatar answered Jul 28 '26 00:07

Ahmad


Try using import statement,If your current page and date.jsp are in same folder.

<c:import url="date.jsp" >

instead of

<jsp:include page="/date.jsp"/ >

N.B: Before using c taglib, import it first and include jstl.jar and standard.jar to your classpath.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
like image 25
Ataur Rahman Munna Avatar answered Jul 28 '26 00:07

Ataur Rahman Munna