盗版牢骚? or 学而不思?
刚学struts2,试着练习教科书上源程序。结果由于印刷(也可能是编者的疏忽)问题,一对双引号悲剧了...
1 package struts2.action;
2
3 import com.opensymphony.xwork2.ActionSupport;
4
5 public class LoginAction extends ActionSupport
6 {
7
8 private String myusername;
9 private String password;
10 private int level=0;
11
12 public String getUsername() {
13 return myusername;
14 }
15 public void setUsername(String username) {
16 this.myusername = username;
17 }
18 public String getPassword() {
19 return password;
20 }
21 public void setPassword(String password) {
22 this.password = password;
23 }
24 //@Override
25 public String execute(){
26 if(!myusername.equals("password")){
27 return INPUT;
28 }
29 else
30 {
31 return SUCCESS;
32 }
33 }
34
35 public int getLevel(){
36 return level;
37 }
38 private void setLevel(int level){
39 this.level=level;
40 }
41 }
由于浮躁,郁闷了老长时间也没看出哪错了:可是照着书上打下来的...最终在同学的帮助检查下,发现第26行"password"加了双引号,由变量变成了常量,结果差多了去了。书本不一定对,自己要学会谨慎思考。