「AOP」の01 sitemesh完全なページ

ページは、時間のいくつかは、ページ上で明示的にインポートJSとCSSの依存関係を持っていない導入を指し、「AOP」と呼ばれます。このセクションでは、興味深い技術sitemeshを説明し、それがページ「AOP」の中で行うことができます。

1、ステップ

  • MavenのWebプロジェクトを作成
    https://www.jianshu.com/p/042073b7710bを
  • 以下の依存性を追加します。
        <dependency>
            <groupId>org.sitemesh</groupId>
            <artifactId>sitemesh</artifactId>
            <version>3.0.1</version>
        </dependency>
  • プロジェクト/ srcに/メイン/ webappの/フォルダ導入jqueryの-1.10.2.jsまたは他のJSで
  • プロジェクト/ srcに/メイン/ webappの/ sitemeshフォルダ作成index.jspの中
<html>
<head>
    <script type="text/javascript">
        $(function () {
            alert("sitemesh起作用了")
        })
    </script>
</head>
<body>
<h2>Hello World!</h2>
</body>
</html>
  • プロジェクト/ srcに/メイン/ webappの/ sitemeshフォルダ作成head.jspで
<script type="text/javascript" src="/jquery-1.10.2.js"></script>
  • プロジェクト/ srcに/メイン/ webappの/ sitemeshフォルダ作成decorator.jspで
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><sitemesh:write property="title"/></title>
    <style type="text/css">
        body {
            font-size: 12px;
        }
    </style>
    <sitemesh:write property="head"/>
    <jsp:include page="/sitemesh/head.jsp"/>
</head>
<body>
</body>
</html>
  • プロジェクトを変更/src/main/webapp/WEB-INF/web.xml
  <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/sitemesh/*</url-pattern>
  </filter-mapping>
  • / srcに/メイン/ webappの/ WEB-INFの追加sitemesh3.xmlで
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
    <mapping path="/sitemesh/*" decorator="/sitemesh/decorator.jsp"/>
</sitemesh>
  • テスト
    プロジェクトを開始するには、訪問index.jspのは、ポップアップ「sitemesh果たす役割を。」が表示されます
    これらは「AOP」の使用sitemesh完全なページです。

おすすめ

転載: www.cnblogs.com/alichengxuyuan/p/12504328.html