在portlet的表单提交后,字段为空

时间:2013-05-13 12:51:41

标签: java portlet

我想提交带有值的表单,并通过portlet中的action方法读取它们,但返回的值为null。这是我的代码,我真的很绝望,因为我没有看到任何错误。

<portlet:actionURL name="calculate" var="calculateAction" />
    <form name="<portlet:namespace/>calculatorForm" action="${calculateAction}" method="post" enctype="application/x-www-form-urlencoded">
         <table>
              <tr>
                 <td><label for="<portlet:namespace/>date">Date</label></td>
                 <td><input type="text" name="<portlet:namespace/>date" id="<portlet:namespace/>date" /></td>
              </tr>
              <tr>
                  <td><label for="<portlet:namespace/>amount">Amount</label></td>
                  <td><input type="text" name="<portlet:namespace/>amount" id="<portlet:namespace/>amount" /></td>
              </tr>
              <tr>
                  <td colspan="2"><input type="submit" value="Calculate" /></td>
              </tr>
        </table>
    </form>

我的方法看起来像这样

@ProcessAction(name = "calculate")
public void calculate(ActionRequest request, ActionResponse response) {
    String stringDate = request.getParameter("date");
    String stringAmount = request.getParameter("amount");
    System.out.println("Amount: " + stringAmount);
    System.out.println("Date: " + stringDate);
}

正确调用方法但两个变量始终为null。任何提示?谢谢

1 个答案:

答案 0 :(得分:1)

由于您已将portlet命名空间添加到每个表单输入中,因此您还需要使用命名空间调用getParameter。尝试使用

request.getParameter(response.getNamespace()+"data");
request.getParameter(response.getNamespace()+"amount");
相关问题