• Jsp Layout 布局页


    本文章仅用于知识记录

    /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="收件箱" />



  • 相关阅读:
    第七周进度总结
    第六周进度总结
    第五周进度总结
    《大道至简》读后感
    第四周进度总结
    第三周进度总结
    第二周进度总结
    第一周进度总结
    top工具
    系统监控的一些工具w , vmstat
  • 原文地址:https://www.cnblogs.com/vmask/p/4893305.html
Copyright © 2020-2023  润新知