我想提交带有值的表单,并通过portlet中的操作方法读取它们,但是返回的值始终为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);
}
已正确调用方法,但两个变量始终为空。
由于您已经在每个表单输入之前添加了portlet命名空间,因此,您还需要使用该命名空间来调用getParameter
。尝试使用
request.getParameter(response.getNamespace()+"data");
request.getParameter(response.getNamespace()+"amount");