Reputation: 31848
What is the JSP equivalent of ASP.NET MVC's partial views?
I'd like to separate some complicated view logic out of a page into a separate page that only handles that logic. How can I render that page as part of my page?
Upvotes: 13
Views: 8660
Reputation: 1108802
There isn't. JSP is not a fullworthy equivalent of ASP.NET MVC. It's more an equivalent to classic ASP. The Java equivalent of ASP.NET MVC is JSF 2.0 on Facelets.
However, your requirement sounds more like as if you need a simple include page. In JSP you can use the <jsp:include>
for this. But it offers nothing more with regard to templating (Facelets is superior in this) and also nothing with regard to component based MVC (there you have JSF for).
Basic example:
main.jsp
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<h1>Parent page</h1>
<jsp:include page="include.jsp" />
</body>
</html>
include.jsp
<h2>Include page</h2>
Generated HTML result:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<h1>Parent page</h1>
<h2>Include page</h2>
</body>
</html>
Upvotes: 20