2013-05-13 123 views
0

我想通过portlet中的action方法提交表单并读取它们,但返回的值是空的。这里是我的代码,我非常绝望,因为我没有看到任何错误。Portlet表单提交后字段为空

<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); 
} 

方法正确调用,但是这两个变量总是空。任何提示?谢谢

回答

1

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

request.getParameter(response.getNamespace()+"data"); 
request.getParameter(response.getNamespace()+"amount"); 
+0

我有没有命名空间相同的错误。但我肯定会尝试这 – 2013-05-13 16:04:41

+0

它实际上工作,谢谢 – 2013-05-14 11:54:26