posts - 5, comments - 1, trackbacks - 0, articles - 2
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          關于Java 接口實現的一個問題

          Posted on 2009-05-17 12:09 bitsun 閱讀(103) 評論(0)  編輯  收藏
          Struts2 Action的接口定義
           1 //The interface of Action
           2 
           3 package com.blackstone;
           4 
           5 public interface Action
           6 {
           7     public static final String SUCCESS="success";
           8     public static final String NONE="none";
           9     public static final String ERROR="error";
          10     public static final String INPUT="input";
          11     public static final String LOGIN="login";
          12     
          13     public String execute()throws Exception;
          14 }
          實現一個LoginAction
           1 //Struts 2的Action類就是一個普通的Java類
           2 package com.blackstone;
           3 
           4 public class LoginAction implements com.blackstone.Action
           5 {
           6     private String username;
           7     private String password;
           8     
           9     public String getUsername()
          10     {
          11         return username;
          12     }
          13     
          14     public String getPassword()
          15     {
          16         return password;
          17     }
          18     
          19     public void setUsername(String username)
          20     {
          21         this.username=username;
          22     }
          23     
          24     public void setPassword(String password)
          25     {
          26         this.password=password;
          27     }
          28     
          29     public String execute()throws Exception
          30     {
          31         if(getUsername().equals("peter")&&getPassword().equals("123"))
          32         {
          33             return SUCCESS;
          34         }
          35         else
          36         {
          37             return ERROR;
          38         }
          39     }
          40 }

          問題:
          編譯Action成功
          編譯LoginAction出錯
          LoginAction.java:4: 找不到符號
          符號: 類 Action
          位置: 軟件包 com.blackstone
          public class LoginAction implements com.blackstone.Action
                                                            ^
          LoginAction.java:33: 找不到符號
          符號: 變量 SUCCESS
          位置: 類 com.blackstone.LoginAction
                                  return SUCCESS;
                                         ^
          LoginAction.java:37: 找不到符號
          符號: 變量 ERROR
          位置: 類 com.blackstone.LoginAction
                                  return ERROR;
                                         ^
          3 錯誤

          解決方法:
          配置CLASSPATH變量,加入com.blackstone包所在的路徑,這樣Java解釋器才能夠定位Action.class,編譯LoginAction.java的時候才不會找不到其中的靜態變量

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 碌曲县| 兴安县| 耒阳市| 富宁县| 合水县| 武定县| 陆良县| 辰溪县| 安庆市| 康定县| 临清市| 尚志市| 游戏| 萝北县| 布尔津县| 乡城县| 奈曼旗| 肇庆市| 敖汉旗| 玉山县| 嘉义市| 土默特左旗| 昌宁县| 寻甸| 安达市| 蓬溪县| 名山县| 商洛市| 策勒县| 保亭| 宜兰市| 拜城县| 丹棱县| 当阳市| 大石桥市| 滦平县| 资中县| 长汀县| 淳安县| 读书| 海原县|