開始備忘記:
[1] 安裝 jdk 5
[2] 下載 Tomcat
[3] 安裝 Eclipse 及 相關 plugins
[4] 實例測試
[1] 安裝 jdk 5:
下載 jdk-1_5_0_07-nb-5_0-win-ml.exe
http://java.sun.com/j2se/1.5.0/download-netbeans.html
安裝至 D:\jdk1.5.0_07
新增環境變數 JAVA_HOME=D:\jdk1.5.0_07
D:\jdk1.5.0_07\bin 加入至 PATH 中
D:\jdk1.5.0_07\lib\dt.jar 及 D:\jdk1.5.0_07\lib\tools.jar 加入至 CLASSPATH 中
執行 D:\>java -version
輸出 java version "1.5.0_07" 即安裝成功.
安裝 Eclipse Callisto plugins:
點擊 c:\eclipse_tptp\eclipse.exe 執行 Eclipse
選擇 Help -> Software Updates -> Find and Install -> Search for new features to install
按 Next 後 點選 Callisto Discovery Site 後 按 Finish
然後選擇最接近的下載點安裝, 然後 隨 C and C++ Developement 外, 全部安裝.
如下圖所示
eclipse_tptp_1.gif
這裡下載安裝使用超過20分鐘. 最好選擇較接近的下載點.
[4] 實例測試:
執行 Eclipse c:\eclipse_tptp\eclipse.exe
切換至
建立測試項目:
File -> New -> Project ->> Web -> Dynamic Web Project 按 Next
Project name : Jasper2Sample
然後按 Finish
右鍵點選 Jasper2Sample -> Properties -> Java Build Path -> Source按 Add Folder 再按 Create New Folder
Folder name : output_servlet
然後按 Finish 及 OK 如下圖所示
切換至 Library
按 Add External JARs
加入
C:\apache-tomcat-5.5.20\common\lib\servlet-api.jar
C:\apache-tomcat-5.5.20\common\lib\jsp-api.jar
C:\apache-tomcat-5.5.20\common\lib\jasper-runtime.jar
然後按 OK
如下圖所示
建立 Jasper Ant Build File:
右鍵點選 Jasper2Sample -> New -> File
File name : build_servlet.xml
然後按 Finish
內容為:
上面
為 tomcat 主目錄位置
為 servlet 輸出目錄位置
為 Web root 位置
建立測試 jsp 檔案:
右鍵點選 WebContent -> New -> File
File name : index.jsp
然後按 Finish
內容為:
pageEncoding="BIG5"%>
Jasper2 Sample產生 Servlet 源檔案:
右鍵點選 build_servlet.xml -> Run As -> Ant Build
然後 Refresh Jasper2Sample Project
就會顯示 output_servlet -> org.apache.jsp.index_jsp.java
內容如下所示:
/********************** index_jsp.java **********************/package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static java.util.List _jspx_dependants;
public Object getDependants() {
return _jspx_dependants;
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;
try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html; charset=BIG5");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\n\n
\n\nJasper2 Sample\n\n\n");out.print("Hello Joeyta" );
out.write("\n\n");
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
/********************** index_jsp.java **********************/
目錄結構如下所示: