jasper与java_Eclipse Tomcat Jasper 入门 - [Matrix - 与 Java 共舞]

開始備忘記:

[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 外, 全部安裝.

如下圖所示

279480_1.gif

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 如下圖所示

279480_2.gif

切換至 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

如下圖所示

279480_3.gif

建立 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 **********************/

目錄結構如下所示:

279480_4.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值