Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSP equivalent of ASP.NET MVC's partial views?

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?

like image 879
C. Ross Avatar asked Nov 26 '10 18:11

C. Ross


People also ask

What is the equivalent to ASP net in Java?

The Java equivalent of ASP.NET (MVC) would be a Java MVC framework. There are a lot of Java-based MVC frameworks out, mostly providing a Servlet/Filter-based controller and taglibs to interact with the model (usually a Javabean) and the view (usually a JSP page, but XHTML is also possible).

How do you call a partial view from a webpage or controller?

You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .

What is partial view in asp net?

A partial view is a Razor markup file ( . cshtml ) without an @page directive that renders HTML output within another markup file's rendered output. The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages.


1 Answers

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>

See also:

  • What is the Java alternative to ASP.NET/PHP?
  • Analogues of Java and .NET technologies/frameworks
  • What is the difference between JSF, JSP and Servlet?
like image 139
BalusC Avatar answered Oct 21 '22 14:10

BalusC