自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Excel File Servlet的創(chuàng)建代碼

開發(fā) 后端
本文介紹Excel File Servlet的創(chuàng)建代碼,以及選擇覆蓋doGet()處理方法和定義Servlet的URL參數(shù)。

1、File->New...->W(wǎng)eb->雙擊Standard Servlet圖標(biāo),啟動(dòng)創(chuàng)建標(biāo)準(zhǔn)Servlet的向?qū)А?/P>

指定Servlet類名為Excel File Servlet,將包名設(shè)為bookstore.servlet,按Next到下一步。

2、選擇覆蓋doGet()處理方法。
◆Servlet:creates content type:unspecified,設(shè)定Servlet的生成文檔的類型,由于這個(gè)Servlet作為一個(gè)Excel文件并以附件的形式下載,需要我們手工設(shè)定Servlet的響應(yīng)內(nèi)容類型。
◆implements methods:doGet(),這樣向?qū)⑸梢粋€(gè)doGet()方法框架。
按Next到下一步。

3、定義Servlet的URL參數(shù)。

點(diǎn)擊Add Parameter在參數(shù)列表出現(xiàn)一個(gè)新行,在新行中定義Servlet的URL參數(shù),其中Name為URL所帶的參數(shù)名,而Variable為 Servlet中對(duì)應(yīng)的變量名,此外還可以通過Desc和Default為變量指定注釋和默認(rèn)值,在Type欄中指定變量的類型。

我們定義了兩個(gè)URL參數(shù),分別是year和month,指定需要下載日志的年份和月份。按Next到下一步。

4.指定servlet的訪問路徑

接受第4步向?qū)O(shè)定的Servlet的名字和訪問路徑,它們分別是:
◆Name:Excel File Servlet
◆URL pattern:/Excel File Servlet

直接按Finish創(chuàng)建Excel File Servlet,其代碼如下所示:

代碼Excel File Servlet.java:

  1. package bookstore.servlet;  
  2. import javax.servlet.*;  
  3. import javax.servlet.http.*;  
  4. import java.io.*;  
  5. import java.util.*;  
  6. public class ExcelFileServlet  
  7. extends HttpServlet  
  8. {  
  9. //Initialize global variables  
  10. public void init()  
  11. throws ServletException  
  12. {  
  13. }  
  14. //Process the HTTP Get request  
  15. public void doGet(HttpServletRequest request, 
    HttpServletResponse response)  
  16. throws ServletException, IOException  
  17. {  
  18. //年份  
  19. String year = request.getParameter("year");  
  20. if (year == null)  
  21. {  
  22. year = "2005";  
  23. }  
  24. //月份  
  25. String month = request.getParameter("month");  
  26. if (month == null)  
  27. {  
  28. month = "1";  
  29. }  
  30. PrintWriter out = response.getWriter();  
  31. //@todo implement GET  
  32. }  
  33. //Clean up resources  
  34. public void destroy()  
  35. {  
  36. }  

【編輯推薦】

  1. Servlet 2.5版本終止響應(yīng)
  2. 創(chuàng)建Servlet過濾器的向?qū)?/FONT>
  3. 淺談user cache Servlet
  4. 過濾器解壓縮Servlet和JSP頁面內(nèi)容
  5. Servlet的Context與Config
責(zé)任編輯:佚名 來源: IT專家網(wǎng)
相關(guān)推薦

2009-07-08 17:33:37

Servlet過濾器

2009-06-08 17:47:00

JavaExcel

2021-02-03 10:31:10

NPOIExcel樣式

2009-07-08 09:35:53

Java ServleServlet 3.0

2009-07-01 15:25:16

Servlet和JSP

2015-11-09 13:03:47

JavaServlet創(chuàng)建二維碼

2009-07-08 10:12:04

Servlet Con

2009-07-07 10:16:42

Servlet引擎

2009-07-09 11:21:40

Servlet注冊(cè)

2009-07-06 09:03:10

Servlet定義

2009-09-01 14:39:47

C#創(chuàng)建Excel文件

2010-07-06 16:52:17

SQL Server創(chuàng)

2010-04-15 14:39:56

Oracle創(chuàng)建表空間

2009-09-01 14:45:45

C#創(chuàng)建Excel文件

2009-08-18 14:25:05

C# 操作Excel

2009-07-09 15:30:53

Servlet容器會(huì)話跟蹤

2009-07-08 11:37:32

Servlet API

2009-07-07 09:51:49

Servlet實(shí)例

2009-07-07 15:01:58

Apache Serv

2009-07-08 15:01:00

Servlet的作用
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)