<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 23,comments - 12,trackbacks - 0

    建目錄coreservlets,將兩個servlets放在這個目錄中,在coreservlet的上級目錄
    運行:
    javac coreservlets/HelloServlet3.java



    package coreservlets;

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    /** Simple servlet for testing the use of packages
     *  and utilities from the same package.
     *  <P>
     *  Taken from Core Servlets and JavaServer Pages 2nd Edition
     *  from Prentice Hall and Sun Microsystems Press,
     *  http://www.coreservlets.com/.
     *  &copy; 2003 Marty Hall; may be freely used or adapted.
     */

    public class HelloServlet3 extends HttpServlet {
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
          throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String title = "Hello (3)";
        out.println(ServletUtilities.headWithTitle(title) +
                    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
                    "<H1>" + title + "</H1>\n" +
                    "</BODY></HTML>");
      }
    }




    package coreservlets;

    import javax.servlet.*;
    import javax.servlet.http.*;

    /** Some simple timesavers. Note that most are static methods.
     *  <P>
     *  Taken from Core Servlets and JavaServer Pages 2nd Edition
     *  from Prentice Hall and Sun Microsystems Press,
     *  http://www.coreservlets.com/.
     *  &copy; 2003 Marty Hall; may be freely used or adapted.
     */

    public class ServletUtilities {
      public static final String DOCTYPE =
        "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
        "Transitional//EN\">";

      public static String headWithTitle(String title) {
        return(DOCTYPE + "\n" +
               "<HTML>\n" +
               "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n");
      }

      /** Read a parameter with the specified name, convert it
       *  to an int, and return it. Return the designated default
       *  value if the parameter doesn't exist or if it is an
       *  illegal integer format.
      */
     
      public static int getIntParameter(HttpServletRequest request,
                                        String paramName,
                                        int defaultValue) {
        String paramString = request.getParameter(paramName);
        int paramValue;
        try {
          paramValue = Integer.parseInt(paramString);
        } catch(NumberFormatException nfe) { // null or bad format
          paramValue = defaultValue;
        }
        return(paramValue);
      }

      public static double getDoubleParameter
                                     (HttpServletRequest request,
                                      String paramName,
                                      double defaultValue) {
        String paramString = request.getParameter(paramName);
        double paramValue;
        try {
          paramValue = Double.parseDouble(paramString);
        } catch(NumberFormatException nfe) { // null or bad format
          paramValue = defaultValue;
        }
        return(paramValue);
      }

      /** Replaces characters that have special HTML meanings
       *  with their corresponding HTML character entities.
       */
     
      // Note that Javadoc is not used for the more detailed
      // documentation due to the difficulty of making the
      // special chars readable in both plain text and HTML.
      //
      // Given a string, this method replaces all occurrences of
      //  '<' with '&lt;', all occurrences of '>' with
      //  '&gt;', and (to handle cases that occur inside attribute
      //  values), all occurrences of double quotes with
      //  '&quot;' and all occurrences of '&' with '&amp;'.
      //  Without such filtering, an arbitrary string
      //  could not safely be inserted in a Web page.

      public static String filter(String input) {
        if (!hasSpecialChars(input)) {
          return(input);
        }
        StringBuffer filtered = new StringBuffer(input.length());
        char c;
        for(int i=0; i<input.length(); i++) {
          c = input.charAt(i);
          switch(c) {
            case '<': filtered.append("&lt;"); break;
            case '>': filtered.append("&gt;"); break;
            case '"': filtered.append("&quot;"); break;
            case '&': filtered.append("&amp;"); break;
            default: filtered.append(c);
          }
        }
        return(filtered.toString());
      }

      private static boolean hasSpecialChars(String input) {
        boolean flag = false;
        if ((input != null) && (input.length() > 0)) {
          char c;
          for(int i=0; i<input.length(); i++) {
            c = input.charAt(i);
            switch(c) {
              case '<': flag = true; break;
              case '>': flag = true; break;
              case '"': flag = true; break;
              case '&': flag = true; break;
            }
          }
        }
        return(flag);
      }
    }

     

    posted on 2005-08-17 11:34 my java 閱讀(1024) 評論(1)  編輯  收藏 所屬分類: java

    FeedBack:
    # re: package編譯
    2008-04-13 22:27 | pobu
    你好,我對package的編譯過程非常迷惑,希望能得到你的幫助!  回復  更多評論
      
    主站蜘蛛池模板: 免费国产99久久久香蕉| 伊人久久亚洲综合影院| 免费电视剧在线观看| 免费播放在线日本感人片| 国产精品亚洲综合一区| 一级特黄aaa大片免费看| 国产性爱在线观看亚洲黄色一级片 | 亚洲免费网站在线观看| 日本不卡在线观看免费v| 国产精品国产亚洲精品看不卡| 亚洲午夜久久久久久尤物| 成年人网站免费视频| 久久久久一级精品亚洲国产成人综合AV区 | 91av免费在线视频| 97无码免费人妻超级碰碰夜夜 | 亚洲va在线va天堂va四虎| 无码精品一区二区三区免费视频| 国产婷婷高清在线观看免费| 亚洲精品综合一二三区在线| 99免费观看视频| 亚洲无成人网77777| 高清永久免费观看| 又粗又硬又大又爽免费视频播放| 亚洲日韩涩涩成人午夜私人影院| 亚洲国产日韩视频观看| 尤物永久免费AV无码网站| 国产成人高清精品免费观看| 久久亚洲国产伦理| 免费高清在线爱做视频| 无遮挡免费一区二区三区| 成人黄18免费视频| 亚洲国产高清精品线久久| 国产成人亚洲合集青青草原精品| 男人进去女人爽免费视频国产| 亚洲熟妇少妇任你躁在线观看无码| 亚洲综合av一区二区三区不卡| 67pao强力打造高清免费| 久久亚洲免费视频| 国产免费av片在线无码免费看| 国产成人亚洲综合网站不卡| 国产91精品一区二区麻豆亚洲 |