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