不要每个属性都 setter getter .. 这样页面很难看。。。 直接 把对象变成一个成员变量会比较好。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package com.wl.csdn.problem; public class User { public String getUserName() { return userName; } public void setUserName(String userName) { this .userName = userName; } public String getPassword() { return password; } public void setPassword(String password) { this .password = password; } public String userName; public String password; } |
Action:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package com.wl.csdn.problem; import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport { public User user; public User getUser() { return user; } public void setUser(User user) { this .user = user; } @Override public String execute() throws Exception { // TODO Auto-generated method stub System.out.println( "userName=" +user.getUserName()); System.out.println( "password=" +user.getPassword()); return SUCCESS; } } |
前台Jsp:
1
2
3
4
5
|
<form action= "login" name= "form1" method= "post" > UserName:<input type= "text" name= "user.userName" class = "width154n" /> Password:<input type= "text" name= "user.password" class = "width154n" /> <a href= "#" onclick= "javascript:document.form1.submit();" >submit form</a> </form> |
前台提交按钮后,后台Action 中就可以获得User对象的值。。。
版权声明:本文为博主原创文章,未经博主允许不得转载。
today lazy . tomorrow die .