template page meggunakan sitemesh

Buat project web menggunakan eclipse JEE

File > New > Dynamic Web Project

Buat file index.html pada WebContent

<!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>Just my code</title>
</head>
<body>
<h5>Template page menggunakan sitemesh</h5>
</body>
</html>

Kemudian jalankan Myweb, klik kanan project Myweb pilih Run As > Run On Server, pada tipe server pilih Basic > J2EE Preview > Finish ..

Kemudian akses web menggunakan alamat http://localhost:8080/Myweb

Download Sitemesh dan JSTL library

Q> sitemesh-2.4.1.jar dan jstl-1.2.jar kemudian letakan (copy) di folder lib project.

Q> Buat folder sitemesh pada WebContent
Q> Buat file main.jsp pada folder sitemesh

<%@taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%@ 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>My Web - <decorator:title /></title>
</head>
<body>
<h2>This about my web ;D</h2>
<hr>
<h4><decorator:title /></h4>
<br/>

<decorator:body />
</body>
</html>

Q> Buat file decorators.xml pada folder WEB-INF

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/sitemesh">
<decorator name="main" page="main.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>

Q> Tambahkan config untuk sitemesh di web.xml

<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Q> Donwload apache-tomcat-6.0.35 > ekstrak di suatu direktory
Q> Masukkan tomcat ke dalam eclipse, menu Window > Show View > Server
Q> Klik kanan > Add server , pilih Apache > Tomcat 6.0 > browse tempat ekstract file apache tomcat tadi.
Q> Start tomcat.
Q> Jalankan lagi Myweb , http://localhost:8080/Myweb

Q> Selesai ;D ,, met ber-sitemesh

Published by

saifiahmada

Begin a big Process with a bit trying

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s