当前位置: 首页 > 工具软件 > JSP Layout > 使用案例 >

Jsp Layout 布局页

仇建茗
2023-12-01

本文章仅用于知识记录

 

/WEB-INF/tags/layout.tag

 1 <%@ tag language="java"  pageEncoding="UTF-8" body-content="empty"%>
 2 <%@ attribute name="file" type="java.lang.String" required="true" %>
 3 <%@ attribute name="title" type="java.lang.String" %>
 4 <%
 5     String contentPage = (String)request.getAttribute("contentPage");
 6     if (contentPage == null) {
 7         contentPage = request.getServletPath();
 8         request.setAttribute("contentPage", contentPage);
 9         request.setAttribute("title", title);
10         request.getRequestDispatcher(file).forward(request, response);
11         throw new SkipPageException();
12     }
13 %>

 


layout.jsp

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE html>
 3 <html lang="en">
 4 <head>
 5     <meta charset="UTF-8">
 6     <title>${title }</title>
 7 </head>
 8 <body>
 9     <jsp:include page="${contentPage }"></jsp:include>
10 </body>
11 </html>

 



test.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    //<% request.setAttribute("base", request.getContextPath());%>
%>
<%@taglib prefix="my" tagdir="/WEB-INF/tags"%>
<my:layout file="layout.jsp" title="收件箱" />

 



转载于:https://www.cnblogs.com/vmask/p/4893305.html

 类似资料: