这是某FTP软件提供的一段代码。我是想做一个在JSP网页主要放一个FTP软件WEB登录代码(这个软件支持WEB和FTP访问)。下面这个例子是他们帮助文件提供的。我就想知道这个怎么用,大神们说的简单点告诉我这个如何实现在JSP网页里。

  • JAVA example:
  • import java.io.*;
  • import java.net.*;
  • - class GetUrlContent {
  • public static void main(String[] args) throws IOException {
  • String strUrl = "http://127.0.0.1:5466/admin_webservice.html";
  • String strUrlParam = "admin=demo&pass=demo123&cmd=";
  • - String strLuaScript = "local nSessionCnt = 0 "+
  • "for _,domain in pairs(c_GetDomainList()) do "+
  • " nSessionCnt = nSessionCnt + c_GetSessionCount(domain) "+
  • "end "+
  • "print(nSessionCnt)"
  • String strResult = SendGetRequest(strUrl, strUrlParam+java.net.URLEncoder.encode(strLuaScript));
  • }
  • - public static String SendGetRequest(String url, String param) {
  • String result = "";
  • try {
  • String urlName = url + "?" + param;
  • URL U = new URL(urlName);
  • URLConnection connection = U.openConnection();
  • connection.connect();
  • BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  • String line;
  • - while ((line = in.readLine()) != null) {
  • result += line;
  • }
  • in.close();
  • } catch (Exception e) {
  • result = "";
  • }
  • return result;
  • }
  • }复制代码