码迷,mamicode.com
首页 > 其他好文 > 详细

struts2接收参数的几种形式

时间:2014-12-14 22:35:36      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   使用   sp   for   

1、使用属性

HTML:

<form action="login" method="post" name="form1">
  用户名:<s:textfield name="username"/><br/>
   密 码:<s:password name="password"/><br/>
               <s:submit value="提交"/> 
 </form>

action:

public class TestAction extends ActionSupport{  
     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;
     }
 }

2、使用类来接收

HTML:

<form action="login" method="post" name="form1">
  用户名:<s:textfield name="users.username"/><br/>
   密 码:<s:password name="users.password"/><br/>
             <s:submit value="提交"/> 
 </form>

Action:

public class TestAction extends ActionSupport{
private Users users;

public Users getUsers(){

return users;

}

public void setUsers(Users users){

this.users=users;

}

Users类:

public class Users{ 
 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;
 }
}

3、使用模型驱动

HTML:

<form action="login" method="post" name="form1">
  用户名:<s:textfield name="username"/><br/>
   密 码:<s:password name="password"/><br/>
               <s:submit value="提交"/> 
 </form>

Action:

public class sysAction extends ActionSupport implements ModelDriven<User>{     
    private User user = new User();  //必须手动实例化   
      
    public User getModel() {        
        return user;  //返回实例   
    }     
}

4、使用传统的request

public class TestAction extends ActionSupport{  
     private static final long serialVersionUID = -7463970150000893325L;  
   
     public void execeute() {  
         String name = super.getRequest().getParameter("paraName");  
         System.out.println("姓名:" + name);  
     }  
 }

 

struts2接收参数的几种形式

标签:style   blog   io   ar   color   os   使用   sp   for   

原文地址:http://www.cnblogs.com/yangzhilong/p/4163112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!