Page To Action bean 映射

方法一

 a.jsp

    <form method="post" action="loginAction.action">
    姓名:<input type="text" name="username"><br>  
 
密码:<input type="text" name="password"><br>
    <input type="submit"/>
    </form>

b   java

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class LoginAction extends ActionSupport implements ModelDriven<User>{   
 
    private User user = new User();    
 
    public User getModel() {   
       return user;   
    }   
    
    
    @Override
    public String execute() throws Exception {
        if ( user !=null)
            System.out.println( "==LoginAction=====username:"+user.getUsername() );
        return SUCCESS;
    }  
}

方法一

 JSP

    <form method="post" action="loginAction2.action">
    姓名:<input type="text" name="user.username"><br>  
 
密码:<input type="text" name="user.password"><br>
<input type="submit"/>
    </form>


java


import com.opensymphony.xwork2.ActionSupport;

public class LoginAction2  extends ActionSupport     {
    private User user = null;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public String execute() throws Exception {
        if ( user !=null)
            System.out.println( "=LoginAction2======username:"+user.getUsername() );
        return SUCCESS;
    }  
    
}

=====================


public class User {
    private String username;   
    
    private String password;

    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;
    }   

}



你可能感兴趣的:(exception,bean,String,user,input,action)