日期:2014-05-20  浏览次数:20694 次

struts2 请求action后传递参数给结果页面的问题
CompanyAction:

package com.jeedroid;

import com.opensymphony.xwork2.ActionSupport;

public class CompanyAction extends ActionSupport {
private String employee;
private float salary;
public String getEmployee() {
return employee;
}
public void setEmployee(String employee) {
this.employee = employee;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
@Override
public String execute()
{
System.out.println(employee);
System.out.print(salary);
return "success";
}
}
struts.xml:
 <action name="company" class="com.jeedroid.CompanyAction">
  <result name="success">
  /Hello.jsp
  </result>
  </action>
如果请求company.action的参数里employee=sldkf&salary=900 当执行过company这个action之后 怎么把这两个参数传递到Hello.jsp里面 ?怎么在Hello.jsp里面接收??

------解决方案--------------------
jsp获取数据有很多种 :常用的 s标签 ognl
在Struts2中request已经被解析,你是无法获取到request中的数据的
Struts2的传值方式是对应你在action中的属性做set get (这些属性要匹配你的javabean,也可以是一个bean对象,或是泛型list)就可以获取前台的数据和对前台输出数据
 
------解决方案--------------------
通过el表达式,如{employee},{salary},当然也可以通过其他方法得到,比如request等