5

I want to create a jsp template which is similar to blade.php. This is a sample page which I want to create from JSP. I went through tags in the jsp template. How can I create the following blade template using jsp.

default.blade.php

<!DOCTYPE html>
<html lang="en">
@include('dashboard.includes.head')
<body>
<div id="wrapper">
<div id="main-container">
<!-- BEGIN TOP NAVIGATION -->
@include('dashboard.includes.nav-top')
<!-- END TOP NAVIGATION -->
<!-- BEGIN SIDE NAVIGATION -->  
@include('dashboard.includes.nav-side')
<!-- END SIDE NAVIGATION -->
<!-- BEGIN MAIN PAGE CONTENT -->
<div id="page-wrapper">
<!-- BEGIN PAGE HEADING ROW -->
<div class="row">
<div class="col-lg-12">
<!-- BEGIN BREADCRUMB -->
@include('dashboard.includes.breadCrumb')
<!-- END BREADCRUMB --> 
<div class="page-header title">
<!-- PAGE TITLE ROW -->
@yield('pageHeader')
</div>
</div><!-- /.col-lg-12 -->
</div><!-- /.row -->
<!-- END PAGE HEADING ROW -->   
<div class="row">
<div class="col-lg-12">
<!-- START YOUR CONTENT HERE -->
@yield('pageContent')
<!-- END YOUR CONTENT HERE -->
</div>
</div>
<!-- BEGIN FOOTER CONTENT -->   
@include('dashboard.includes.footer')
<!-- END FOOTER CONTENT -->
</div><!-- /#page-wrapper -->   
<!-- END MAIN PAGE CONTENT -->
</div>
</div>
@include('dashboard.includes.scripts')
</body>
</html>
Nuran
  • 331
  • 3
  • 14
  • I clarified your question a bit, but it is still answerable with "yes" (there is a source) or "no" (there is no such source). Would you not rather be interested in "where can I find source and/or examples that do XYZ?". If that is so, change your question, by editing it further, accordingly. – Anthon Mar 07 '15 at 07:30
  • I have edited that phase as follows. "How can I create the following blade template using jsp?" – Nuran Mar 08 '15 at 06:44

1 Answers1

2

JSPs are similar to PHP in that respect that anything that's there and doesn't have a special meaning is printed literally. Thus most of your file should be copied to the JSPs as is. I see two types on control statements: @include and @yield.

Regarding @include: in JSPs you have two ways of doing includes: <%@include ...> and < jsp:include >. The first one includes statically, so it's as if the included file were literally at the position of the include. The second one includes dynamically, that is through an internal HTTP request. Both have advantages and disadvantages. The first version has best performance but you can't use recursive includes. Details are explained elsewhere, look up some tutorials or read on StackOverflow, e.g. here: https://www.tutorialspoint.com/jsp/include_directive.htm and here: Include another JSP file

Regarding @yield: As I don't know blade, I can only guess what it does, but it seems to render some part of the page based on some data from another source. That's where things start depending on the framework you're working with. If it's a plain JSP (hardly used anymore nowadays), you could create a bean that delivers the values for you. Check for example here for more information: https://www.javatpoint.com/jsp-useBean-action . If you're working on some framework, you should read their documentation about how to create a so-called model (https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) and how to access it from within your JSP. In Spring-MVC, for instance, you'd save Java objects in a model that you can inject into your request handler using a Model or ModelMap typed argument. Those values are then accessible from the JSP by using ${nameofmodelattribute} or ${nameofmodelattribute.property}. Check here for a controller example and further reading: https://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-controller

If you give more specifics about your Java frameworks in use, maybe someone can help with more specific answers to your question. In general there's a whole lot of resources about anything surrounding JSPs. Since you seem to be a beginner, I'd recommend that you start a tutorial with a java-based MVC framework of your choice, and starting from their working examples you can start adding your own code, rather than openly asking how to convert your template.

TXN
  • 101
  • 6