为什么在struts1的action中获取的页面表单数据是空字符串?
在jsp中,如下:
<form action="sty.do?do=doSticky" method="post">
<table style="margin-left: 40px;">
         <tr>
        <td>填入置顶数:</td>
<td><input type="text" id="top" name="info.top"/></td>
<td><input type="submit" value="提交"/></td>
</tr>
</table>
</form>
在action中,如下:
public ActionForward doSticky(ActionMapping mapping, ActionForm form,
 HttpServletRequest request, HttpServletResponse response){
try {
StickyForm stickyForm = (StickyForm)((DynaActionForm)form).get("info");
System.out.println(request.getParameter("info.top"));
System.out.println("action中的"+stickyForm.getTop()+"nghhnmjjmm");
                      }
request.getParameter("info.top")结果为空字符串,为什么?
Struts

解决方案 »

  1.   

    你这写的真乱,info是一个类吗,它在stickyForm中有没有get,set()。
    StickyForm stickyForm = (StickyForm)form;这样就能拿到form表单提交的值
    你这样写:
    StickyForm stickyForm = (StickyForm)((DynaActionForm)form).get("info");
    有什么意义
      

  2.   

    LZ,请使用struts1标签库:
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
    你的表单必须改成这样的:<html:form>
      

  3.   

    info是在struts-config.xml中配置的ActionForm类,
    <form-bean name="Sty" type="org.apache.struts.action.DynaActionForm">
    <form-property name="info" type="com.cityctrl.web.form.StickyForm"></form-property>
    </form-bean>
    在StickyForm类中,有
    public String getTop() {
    return top;
    }

    public void setTop(String top) {
    this.top = top;
    }
    DynaActionForm)form表示动态ActionForm