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

創(chuàng)新互聯(lián)專(zhuān)注為客戶(hù)提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都做網(wǎng)站、成都網(wǎng)站建設(shè)、朔城網(wǎng)絡(luò)推廣、微信小程序開(kāi)發(fā)、朔城網(wǎng)絡(luò)營(yíng)銷(xiāo)、朔城企業(yè)策劃、朔城品牌公關(guān)、搜索引擎seo、人物專(zhuān)訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供朔城建站搭建服務(wù),24小時(shí)服務(wù)熱線(xiàn):18980820575,官方網(wǎng)址:www.cdcxhl.com
指定Servlet類(lèi)名為Excel File Servlet,將包名設(shè)為bookstore.servlet,按Next到下一步。
2、選擇覆蓋doGet()處理方法。
◆Servlet:creates content type:unspecified,設(shè)定Servlet的生成文檔的類(lèi)型,由于這個(gè)Servlet作為一個(gè)Excel文件并以附件的形式下載,需要我們手工設(shè)定Servlet的響應(yīng)內(nèi)容類(lè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)的變量名,此外還可以通過(guò)Desc和Default為變量指定注釋和默認(rèn)值,在Type欄中指定變量的類(lèi)型。
我們定義了兩個(gè)URL參數(shù),分別是year和month,指定需要下載日志的年份和月份。按Next到下一步。
4.指定servlet的訪問(wèn)路徑
接受第4步向?qū)O(shè)定的Servlet的名字和訪問(wèn)路徑,它們分別是:
◆Name:Excel File Servlet
◆URL pattern:/Excel File Servlet
直接按Finish創(chuàng)建Excel File Servlet,其代碼如下所示:
代碼Excel File Servlet.java:
- package bookstore.servlet;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.io.*;
- import java.util.*;
- public class ExcelFileServlet
- extends HttpServlet
- {
- //Initialize global variables
- public void init()
- throws ServletException
- {
- }
- //Process the HTTP Get request
- public void doGet(HttpServletRequest request,
HttpServletResponse response)- throws ServletException, IOException
- {
- //年份
- String year = request.getParameter("year");
- if (year == null)
- {
- year = "2005";
- }
- //月份
- String month = request.getParameter("month");
- if (month == null)
- {
- month = "1";
- }
- PrintWriter out = response.getWriter();
- //@todo implement GET
- }
- //Clean up resources
- public void destroy()
- {
- }
- }
名稱(chēng)欄目:ExcelFileServlet的創(chuàng)建代碼
網(wǎng)頁(yè)網(wǎng)址:http://m.fisionsoft.com.cn/article/cceghpd.html


咨詢(xún)
建站咨詢(xún)
