日期:2014-05-18  浏览次数:20690 次

关于struts2对form表单和ajax请求中参数的ognl注入
实体Model

public class Model {

private String string;
private int integer;
private float floatNum;
private boolean bl;
/**
 * @return the floatNum
 */
public float getFloatNum() {
return floatNum;
}
/**
 * @param floatNum the floatNum to set
 */
public void setFloatNum(float floatNum) {
this.floatNum = floatNum;
}

public void setString(String string) {
this.string = string;
}
/**
 * @return the integer
 */
public int getInteger() {
return integer;
}
/**
 * @param integer the integer to set
 */
public void setInteger(int integer) {
this.integer = integer;
}
/**
 * @return the bl
 */
public boolean getBl() {
return bl;
}
/**
 * @param bl the bl to set
 */
public void setBl(boolean bl) {
this.bl = bl;
}
/**
 * @return the string
 */
public String getString() {
return string;
}

action

public class TestAction extends ActionSupport {

/**
 * 
 */
private static final long serialVersionUID = 8813730529644729302L;

private Model model;
    private float floatNum;
    private boolean bl;
    private int integer;
    public void setInteger(int integer) {
this.integer = integer;
}
    public void setBl(boolean bl) {
     this.bl = bl;
    }
  public void setFloatNum(float floatNum) {
this.floatNum = floatNum;
}
public void setModel(Model model) {
this.model = model;
}
private String string;
public void setString(String string) {
this.string = string;
}

public void test() {
JSONObject jsonObj=new JSONObject();
if(model!=null)
{
System.out.println("model中的:"+model.getString()+" | "+model.getInteger()+" |"+model.getFloatNum()+" |"+model.getBl());
}
System.out.println("action中的 :"+string+" |"+integer+"|"+floatNum+"| "+bl);
System.out.println("---------------------------------");
Enumeration<?> enu = ServletActionContext.getRequest()
.getParameterNames();
while (enu.hasMoreElements()) {
String paraName = (String) enu.nextElement();
System.out.println(paraName + ": "
+ ServletActionContext.getRequest().getParameter(paraName));
}
RequestDispatcher rd=ServletActionContext.getRequest().getRequestDispatcher("/呵呵.jsp");
try {
rd.forward(ServletActionContext.getRequest(),ServletActionContext.getResponse());
}&nb