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

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

          Posted on 2009-05-17 12:09 bitsun 閱讀(110) 評論(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的時候才不會找不到其中的靜態變量

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


          網站導航:
           
          主站蜘蛛池模板: 汾西县| 克拉玛依市| 锡林郭勒盟| 东宁县| 三门峡市| 嘉善县| 泾阳县| 馆陶县| 武义县| 绥江县| 沂南县| 鲁甸县| 庆城县| 临猗县| 黑龙江省| 永州市| 秭归县| 湘乡市| 瓮安县| 乌什县| 玉树县| 田东县| 海阳市| 肥乡县| 桃园市| 册亨县| 利辛县| 格尔木市| 紫阳县| 古丈县| 天气| 奉贤区| 高台县| 锡林郭勒盟| 历史| 昔阳县| 当涂县| 昌邑市| 上林县| 蓬安县| 永州市|