zoukankan      html  css  js  c++  java
  • Struts2 数据驱动

    servlet中获取页面传递过来的数据的方式是:request.getParameter(“username”);这个代码可以获取到页面的username的数据。在action中可以通过属性驱动的方式来获取页面的值。

    例子:

    jsp请求页面

    <form action="propertydriver/propertyDriverAction_testPropertyDriver.action" method="post">
        	用户名:<input type="text" name="username"/>
        	密码:<input type="password" name="password"/>
    		<input type="submit"/>
        </form>
    

      

    Action内容

    public class PropertyDriverAction 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;
    	}
    	
    	public String testPropertyDriver(){
    		System.out.println(this.username);
    		System.out.println(this.password);
    		return SUCCESS;
    	}
    }
    

      

    * 属性驱动的执行过程:
    * 在页面上提交了一个url,这个url将被ParametersInterceptor拦截,这个拦截器的功能是
    * 获取页面上的表单中的值
    *
    * 因为这个时候,action已经在对象栈中,所以action中的属性就在栈中,所以可以给栈中的属性赋值

    说明:

      1、 页面中name的属性和action中的属性必须保持一致。

      2、 Action中的属性必须有getset方法。

      3、 满足这两个条件就实现了属性驱动。

  • 相关阅读:
    C++默认参数
    C语言中volatile关键字的作用
    CURL超时处理
    C语言中全局变量、局部变量、静态全局变量、静态局部变量的区别
    unix时间戳和localtime
    !!的用处
    linux中grep和egrep的用法
    非阻塞,send后马上close消息能成功发出去吗
    .hpp与.h的区别
    14课作业答疑
  • 原文地址:https://www.cnblogs.com/callyblog/p/7544944.html
Copyright © 2011-2022 走看看