5.1 kalebu
Ana sawetara arahan sihir liyane sing dakkarepake. Pituduh kang kapisan yaiku direktif kalebu . Ngidini sampeyan nglebokake file liyane ing panggonan kaca sing dituduhake. Format umum arahan kasebut yaiku:
<%@ include file="url"%>
Sampeyan bisa nemtokake ora mung file, nanging, contone, liyane jsp-servlet, utawa malah url.
Tuladha:
<%@ include file="header.jsp"%>
<%
double num = Math.random();
if (num > 0.95) {
out.print(num);
}
%>
<%@ include file="footer.jsp"%>
Contone, sampeyan bisa nyelehake sisih ndhuwur kabeh kaca situs ing header.jsp, lan sisih ngisor ing footer.jsp lan ngumpulake kabeh kaca minangka konstruktor.
5.2 maju
Elinga yen servlet klasik nduweni kemampuan kanggo ngarahake utawa nerusake menyang url liyane? Ing JSP, iki uga bisa ditindakake lan ana tumindak khusus kanggo iki. Penampilane rada beda karo sing sampeyan deleng sadurunge:
<jsp:forward page="url"/>
Ana uga pilihan sing luwih maju - kanthi paramèter:
<jsp:forward page="url" >
<jsp:param name="Name" value="meaning"/>
<jsp:param name="Name" value="meaning"/>
<jsp:param name="Name" value="meaning"/>
</jsp:forward>
Tuladha:
<html>
<head>
<title>The Forward Example</title>
</head>
<body>
<center>
<h2> Forward example </h2>
<jsp:forward page="login.jsp"/>
</center>
</body>
</html>
5.3 Pangalihan
Ora ana arahan khusus kanggo pangalihan, nanging bisa ditindakake kanthi nelpon kode Jawa.
Tuladha:
<body>
<%
String redirectURL = "https://codegym.cc/";
response.sendRedirect(redirectURL);
%>
</body>
Conto iki bakal ngirim 302
pangalihan. Yen sampeyan butuh 301
pangalihan, sampeyan kudu nulis sawetara baris kode liyane:
<body>
<%
response.setStatus(301);
response.setHeader("Location", "https://codegym.cc/");
response.setHeader("Connection", "close");
%>
</body>