程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> jsp+java類+servlet實現文件讀取、寫入的功能(二)

jsp+java類+servlet實現文件讀取、寫入的功能(二)

編輯:關於JSP

本文是根據tomcat平台下實現而做,文件目錄為:
 tom_homewebapps ews下:
└html
└WEB-INF
└classes
    └com
      └FileMan.class
      └FileServlet.class
 └web.xml
接著我們先實現servlet:FileServlet .java
/*
 * FileServlet.java
 *
 * Created on 2005年6月19日, 下午3:03
 */
package com;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.PageContext;
/**
 *
 * @author  淘特網
 * @version
 */
public class FileServlet extends HttpServlet {

    ServletContext sc;
    /** Initializes the servlet.
     */
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        sc=config.getServletContext();

    }

    /** Destroys the servlet.
     */
    public void destroy() {

    }

    /** Processes requests for both HTTP GET and POST methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        //* TODO output your page here

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved