介紹如何使用include,以下拉式選單為例
1.先開發好需要的模組,例如一個下拉式選單
nameSel.jsp
<select name="name">
<option value="johnny">Johnny</option>
<option value="akey">Akey</option>
<option value="Mary">Mary</option>
</select>
2.需要此模組就可以使用include的方式加進來
samInclude.jsp
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<form action="showName.jsp" method="POST">
Please select a name :<jsp:include page="nameSel.jsp"/>
<input type="submit" name="submit" value="Send"/>
</form>
3.最後檢示一下是否可行,把下拉式選單的結果秀出來
showName.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<%
String getname = request.getParameter("name");
%>
Select name is : <%=getname%>