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

          關于Java 接口實現(xiàn)的一個問題

          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 }
          實現(xiàn)一個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的時候才不會找不到其中的靜態(tài)變量

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


          網站導航:
           
          主站蜘蛛池模板: 黑水县| 遵化市| 山阳县| 诏安县| 吴江市| 张家港市| 浦县| 峨眉山市| 顺平县| 姜堰市| 沿河| 云龙县| 漳平市| 马边| 当阳市| 宣武区| 揭西县| 河曲县| 田东县| 靖州| 九江县| 冕宁县| 阿城市| 溆浦县| 镇远县| 万全县| 九江县| 恩施市| 荔浦县| 阿坝县| 丹寨县| 紫阳县| 师宗县| 昌宁县| 英山县| 响水县| 台州市| 油尖旺区| 隆子县| 高唐县| 成安县|