struts2在action中获得页面的值,我在页面有个文本  姓名:<input type="text" name="customer.custName"/>
   public String add() throws Exception{
       System.out.println(request==null);//打印false
System.out.println(request.getParameter("requestName"));//打印null

return "";
    }
在action中打印为null
如果在action中设置request属性在页面可以获得,但是从页面传递到action中就为null郁闷

解决方案 »

  1.   

      S2是属性驱动的
       你在actinon 中定义 custName 属性并生产相应的get和set方法就好了。
       
      

  2.   

    <input type="text" name="customer.custName"/> 这里你写的是"customer.custName",request.getParameter想要的到对应的值必须用“customer.custName”,个人感觉你的配置还是有问题的,自己在好好看看吧。
      

  3.   

    你要在你action中添加一个customer这个对象,然后设置他的get和set方法,你就 可以得到customer的custName这个属性了
      

  4.   

    struts2 跟 1 的取值方法不一样的2中这样取肯定不行给字段 get/set方法, 然后你在action 中 直接customer.getCustName()就能取到了不需要request.getParamter()
      

  5.   

    假设在Action类里有这么一个变量private String str = "Hello jsp and struts2";还必须有str的get方法。在JSP页面我们要引入org.apache.struts2.ServletActionContext
    <%@page import="org.apache.struts2.ServletActionContext"%>然后
    <%
    String str = request.getAttribute("str");
    System.out.println(str); //结果将输出: Hello jsp and struts2
    %>参考:http://www.phome.asia/forum/thread/22792.html