本教程適合 JSP 初學者,透過逐步範例講解核心概念。建議先閱讀 FAQ 完成伺服器設定,再動手實作。
<table border="0" width="400" cellspacing="0" cellpadding="0">
<tr>
<td height="150" width="150"> </td>
<td width="250"> </td>
</tr>
<tr>
<td width="150"> </td>
<td align="right" width="250">
<img src="duke.waving.gif">
</td>
</tr>
</table><br>
<%@ page info="a hello world example" %>
<html>
<head><title>Hello, World</title></head>
<body bgcolor="#ffffff" background="background.gif">
<%@ include file="dukebanner.html" %>
<table>
<tr>
<td width=150> </td>
<td width=250 align=right><h1>Hello, World!</h1></td>
</tr>
</table>
</body>
</html>
<%@ page info="a hello world example" %>
提供頁面說明資訊,不影響輸出。良好習慣:置於檔案最前端,<html> 之前。
<%@ include file="dukebanner.html" %>
在編譯階段將指定檔案內容靜態合併。適用於重用版權聲明、導覽列、共用片段。被引入檔案可為 HTML 或 JSP 片段。
<jsp:useBean> 不能寫成 <jsp:usebean>。../jswdk-1.0/examples/jsp/tutorial/helloworld/background.gif、duke.waving.gif、dukebanner.html、helloworld.jspcd ../jswdk-1.0startserverhttps://yourMachineName:8080/examples/jsp/tutorial/helloworld/helloworld.jspJAVA_HOME 未設定或設定錯誤。DOS 下輸入 set 檢查環境變數。掌握基本頁面結構與 include 重用後,建議繼續學習:
jsp:include、jsp:forward、jsp:plugin)。動手實作是掌握 JSP 最快的途徑,祝學習順利!