码迷,mamicode.com
首页 > Web开发 > 详细

Jsp Layout 布局页

时间:2015-10-19 23:43:35      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:

本文章仅用于知识记录

 

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

 



Jsp Layout 布局页

标签:

原文地址:http://www.cnblogs.com/vmask/p/4893305.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!