Belajar Forward
1.Forward1.Jsp
Coding :
a.forward1.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String name = request.getParameter("firstname");
if(name != null){
%>
<jsp:forward page="forward2.jsp"> <--panggil dari forward 2-->
<jsp:param name="date" value="<%=new java.util.Date() %>" />
</jsp:forward>
<%
}else{
%>
<form method="POST" action="forward1.jsp"><-- form input forward1-->
Input Nama : <input type="text" name="firstname" /><-- input firstname-->
<input type="submit" name="simpan" value="Submit" /><--Button submit untuk proses forward-->
</form>
<% }%>
</body>
</html>
b.forward2.jsp
Coding :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
.big{
font-family: tahoma;
font-weight: bold;
font-size: 2em;
}
</style>
</head>
<body>
<p class="big" >
Hello : <%=request.getParameter("firstname")%><br /> <--Lempar attribut ke forward 1 -->
Request telah diterima <br /> dan data juga telah terforward
</p>
<table style="border:6px outset;">
<tr>
<td style="background-color: black;" >
<p class="big" style="color: cyan;">
<%=request.getParameter("date")%>
</p>
</td>
</tr>
</table>
</body>
</html>
Tidak ada komentar:
Posting Komentar