今天为网友提供的是JAVA源码

源代码在线查看: lpcheckfile.java

软件大小: 4101 K
上传用户: haibokaishi2006
关键词: JAVA 源码
下载地址: 免注册下载 普通下载 VIP

相关代码

				package com.power.pipeengine;
				
				import java.io.*;
				import javax.servlet.*;
				import javax.servlet.http.*;
				import java.util.*;
				
				public class LPCheckFile extends HttpServlet{//extends HttpServlet{
				    public String _str = "";
				
				    /**
				     * Process incoming HTTP GET requests
				     *
				     * @param request Object that encapsulates the request to the servlet
				     * @param response Object that encapsulates the response from the servlet
				     */
				    public void doGet(
				        javax.servlet.http.HttpServletRequest request,
				        javax.servlet.http.HttpServletResponse response)
				        throws ServletException, IOException {
				        doPost(request,response);
						System.out.println("Nothing to do when GET method.");
				    }
				    /**
				     * Process incoming HTTP POST requests
				     *
				     * @param request Object that encapsulates the request to the servlet
				     * @param response Object that encapsulates the response from the servlet
				     */
				    public void doPost(
				        javax.servlet.http.HttpServletRequest request,
				        javax.servlet.http.HttpServletResponse response)
				        throws ServletException, IOException {
				
				        /**** Initialize Writer ****/
				        response.setContentType("text/html");
				        PrintWriter out = response.getWriter();
				        response.setStatus(HttpServletResponse.SC_OK);
				        String _FileName = request.getParameter("FileName");
				        String _LogPath = request.getParameter("LogPath");
				
				        /**** Check File Exists ****/
				        System.out.println("Check File exists --> " + _FileName);
				        RandomAccessFile ccc = null;
				        try {
				            ccc = new RandomAccessFile(_FileName,"r");
				            out.println(ccc.length()>1?"found":"not found");
				
				            //clear Log File
				            if (_LogPath != null && ccc.length()>1) {
				                File file = new File(_LogPath);
				                while (!file.exists() || file.length()==0) {}
				                System.out.println("Clear Log file -->  "+_LogPath + " " +
				                                   (file.delete()?"OK":"failed."));
				            }
				        }
				        catch (FileNotFoundException ex) {
				            out.println("not found");
				        }
				        finally {
				            if (ccc != null ) ccc.close();
				        }
				        System.out.println();
				    }
				    /**
				     * Returns the servlet info string.
				     */
				    public String getServletInfo() {
				        return super.getServletInfo();
				    }
				    /**
				     * Called whenever the part throws an exception.
				     * @param exception java.lang.Throwable
				     */
				    private void handleException(java.lang.Throwable exception) {
				        System.out.println("--------- UNCAUGHT EXCEPTION ---------");
				        exception.printStackTrace(System.out);
				    }
				    /**
				     * Initializes the servlet.
				     */
				    public void init(ServletConfig config) throws ServletException {
				        // insert code to initialize the servlet here
				        super.init(config);
				    }
				    /**
				     * Initialize the class.
				     */
				    /* WARNING: THIS METHOD WILL BE REGENERATED. */
				    private void initialize() {
				        try {
				        } catch (java.lang.Throwable ivjExc) {
				            handleException(ivjExc);
				        }
				    }
				
				    /**
				     * Process incoming requests for information
				     *
				     * @param request Object that encapsulates the request to the servlet
				     * @param response Object that encapsulates the response from the servlet
				     */
				    public void performTask(
				        javax.servlet.http.HttpServletRequest request,
				        javax.servlet.http.HttpServletResponse response) {
				        //System.out.println("performTask() method is called.");
				    }
				    /**
				     * service method comment.
				     */
				    public void service(HttpServletRequest request, HttpServletResponse response)
				        throws javax.servlet.ServletException, java.io.IOException {
				        response.setContentType("text/html");
				        PrintWriter out = response.getWriter();
				
				        String sMethod;
				        sMethod = request.getMethod();
				        if (sMethod.equals("GET"))
				            doGet(request, response);
				        else
				            doPost(request, response);
				    }
				}
				
							

相关资源