Spring - Template page based on many JSP pages - java

How can I build an template page, based on many JSP pages with Spring?
I can not use tag, because I have to set some data to those pages first. I also do not want to implement whole template page ( header, footer ) in every JSP file because only ${content} var will be changing.
Thanks in advance

Use a jsp fragment within your jsp:
<%#include file="header.jspf" %>

Related

Pass parameters to jsp by <%# include file

I need to pass params to included jsp
<%# include file="second.jsp" %>
i need to use it several times in one jsp page, so i need to pass id.
I can't use jsp:include because jsp can't see struts action in this way
Can u help me? Thank you
Set them as attributes on the request object (which makes them visible to the ${var} syntax) before invoking your include.
See How to access a request attribute set by a servlet in JSP? for a similar question.

How to add other html file in thymeleaf,Is it OK ?

As you know,if we want to include other pages in jsp(most are header 、footer), we can write that in our jsp file:
<jsp:include page="/pages/common/header.jsp"></jsp:include>
if I want to  achieve the same function that adding some html file in thymeleaf template , how can I do? Is it OK ?
No, you can’t include jsp files in thymeleaf. But you can include other thymeleaf pages. See how :
Difference between th:insert and th:replace (and th:include)

How to print JSON response from JAVA method to HTML Table?

I have a jsp code, where I fetch some JSON data from JAVA Class file. [Basically openfire users]
Now I get the data successfully, but I want to show this data in HTML table format.
How do I Do this ?
My JSP Code :
<%# page language="java" import="prov.*, java.util.*, java.io.*,java.text.*" contentType="text/html"%>
<%# page errorPage="error.jsp" %>
<%
Openfire tc = new Openfire();
tc.getUsers("192.168.50.218","epvFjHq5RHA614C7");
out.println("Data Is As Below : " + tc.getUsers("192.168.50.218","epvFjHq5RHA614C7"));
%>
And I get Response from the JAVA Class method like this :
[{"username":"abcd","name":"","properties":null},{"username":"admin","email":"admin#example.com","name":"Administrator","properties":null},{"username":"bizdd456d454mnc","email":"bizMNC#bizrtc.com","name":"bidzMNC","properties":null},{"username":"bizddd454mnc","email":"bizMNC#bizrtc.com","name":"bidzMNC","properties":null},{"username":"bizmnc","email":"admin#example.com","name":"511515151515151","properties":{"property":[{"#key":"console.order","#value":"session-summary=1"},{"#key":"console.rows_per_page","#value":"user-summary=8"}]}},{"username":"dhaval","email":"dhaval#bizrtc.com","name":"dhaval","properties":null},{"username":"keyur","email":"keyur#bizrtc.com","name":"keyur","properties":null},{"username":"minz","email":"bizMNC#bizrtc.com","name":"bidzMNC","properties":null},{"username":"patel","email":"rau#example.com","name":"patelbhai","properties":{"property":[{"#key":"console.order","#value":"session-summary=1"},{"#key":"console.rows_per_page","#value":"user-summary=8"}]}},{"username":"rajan","email":"rajan#bizrtc.com","name":"rajan","properties":null},{"username":"+username+","email":"+email+","name":"+name+","properties":null}]
As I am very new to JAVA and JSP I don't know how to parse this data to HTML Table.
So Please help.
You can see here how to do it. You can populate it in Javasript or jQuery, but it is better to use JSTL and not just call java code inside JSPs.
I would suggest you use mustache als template engine.
It allows you to use a HTML fragment as template (store it as resource) where double curly brackets (hence the name Mustache) denote the insertion points.
The full documentation of the Mustache syntax is here and a Java example here. Let us know how it is going.

Freemarker - Reload Template

I have a page whereby I am including a freemarker FTL in this way:
<#include "header.ftl">
Now, the page that it is in does not reload as it's a one pager. However, I would like that at a certain point I refresh header.ftl without doing a full page refresh. Is this possible by any chance? I am new to FTL.
You'll need two serverside endpoints, one for the whole page and another for the fragment(s).
You can then use an ajax request to refresh the fragment (eg jquery)

How to access a decorated jsp pages from with another decorated jsp view

its some how difficult to explain it in simple words . But , I will try as much as possible.
Here is the thing :
I have jsp page FAQ in Spring MVC that uses a decorator called decorator.static.jsp
when ever a request comes to /myapp/static/** ,ok?
Then , after for a page after login I use a decorator like /myapp/secured/** then apply
decorator.secured.jsp
The problem is I have a menu on the bottom of the app like
FAQ | AboutUs | Home
and when i click on FAQ the app goes to
secure/home
instead
/myapp/static/faq/controller
How can I access static pages with like FAQ after I login.
Please , let me know if I have to explain more , Thank you Guys!
Put the top menu in a different html file say menu.html
Now include this html page on your JSP page as :
<%#include file="menu.html" %>

Categories