struts2的ajax提交表单,关于struts2对form表单和ajax请求中参数的ognl注入解决方案

关于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());

} catch (ServletException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

System.out.println("============================");

}

}

jsp页面

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

%>

html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

">

$(function(){

$('button').click(function(){

$.post('test.action',{'model.string':'字符串','model.floatNum':3.1415,'model.integer':1,'model.bl':true},function(data){

$('div').text(data);

});

});

});

/test.action" method="post">

按钮

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值