为什么在提交FormPanel后没有执行onSubmitComplete()?

时间:2016-08-06 17:54:03

标签: servlets gwt

我有一张提交信用卡信息数据的表格:

<g:FormPanel ui:field="creditCardForm" action="/app/create-credit-card" method="post">
    <g:HTML>
        <input data-braintree-name="number" value="4111111111111111"/>
        <input data-braintree-name="cvv" value="100"/>

        <input data-braintree-name="expiration_date" value="10/20"/>

        <input data-braintree-name="postal_code" value="94107"/>
        <input data-braintree-name="cardholder_name" value="John Smith"/>
    </g:HTML>
   </g:FormPanel>

但由于某种原因,SubmitCompleteHandler完成POST后,this.creditCardForm.addSubmitHandler(new SubmitHandler() { @Override public void onSubmit(SubmitEvent event) { LOGGER.fine("onSubmit()"); } }); this.creditCardForm.addSubmitCompleteHandler(new SubmitCompleteHandler() { @Override public void onSubmitComplete(SubmitCompleteEvent event) { LOGGER.fine("complete .."); LOGGER.fine("Submit result: " + event.getResults()); } }); 才会生效:

String

Servlet仅重新生成public class CreateCreditCardServlet extends HttpServlet implements Servlet { private final static Logger LOGGER = Logger.getLogger(CreateCreditCardServlet.class.getName()); @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { LOGGER.debug("#########################################################"); LOGGER.debug("doPost"); LOGGER.debug("#########################################################"); resp.getOutputStream().println("This is servlet response"); } } 并写入一些调试消息:

  $strings = [
        'This is +1% better than last time!',
        'This is +2% better than last time!',
        'This is +3% better than last time!',
        'This is +4% better than last time!',
        'This is +5% better than last time!',
        ...
    ];

  // Psuedo code

我在开发人员工具中看到了响应,但为什么处理程序没有被调用?

1 个答案:

答案 0 :(得分:1)

来自FormPanel文档:

  

后端服务器应以内容类型响应   'text / html',表示返回的文本将被视为HTML。   如果服务器指定了任何其他内容类型,则结果   在onFormSubmit事件中发送的HTML将无法预测   浏览器和onSubmitComplete事件可能根本不会触发。

因此,在servlet中你需要做类似的事情:

resp.setContentType("text/html")