內容類型是“應用程序/x-www-form-urlencoded”。預期的“文本/x-gwt-rpc” (Content-Type was 'application/x-www-form-urlencoded'. Expected 'text/x-gwt-rpc')


問題描述

內容類型是“應用程序/x‑www‑form‑urlencoded”。預期的“文本/x‑gwt‑rpc” (Content‑Type was 'application/x‑www‑form‑urlencoded'. Expected 'text/x‑gwt‑rpc')

我正在嘗試將 Spring Security 與 GWT 一起使用,但我在一個又一個問題中遇到了問題,因為似乎沒有什麼能像它實際應該那樣工作。目前我正在嘗試將所有內容連接到我的自定義登錄頁面。為此,我有一個 FormPanel,它的初始化如下:

public LoginViewImpl() {
    initWidget(uiBinder.createAndBindUi(this));

    this.frmLogin.setMethod(FormPanel.METHOD_POST);
    this.frmLogin.setAction("/app/login");
    this.frmLogin.setEncoding("text/x‑gwt‑rpc");

    this.txtUserID.setName("username");
    this.txtPassword.setName("password");
}

但是當我點擊登錄按鈕時,我得到:

javax.servlet.ServletException: Content‑Type was 'application/x‑www‑form‑urlencoded'. Expected 'text/x‑gwt‑rpc'.
    at com.google.gwt.user.server.rpc.RPCServletUtils.checkContentTypeIgnoreCase(RPCServletUtils.java:477)
    at com.google.gwt.user.server.rpc.RPCServletUtils.readContent(RPCServletUtils.java:209)
    at com.google.gwt.user.server.rpc.RPCServletUtils.readContentAsGwtRpc(RPCServletUtils.java:252)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.readContent(AbstractRemoteServiceServlet.java:182)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:364)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    ...

我沒有不知道如何避免這種情況。任何幫助表示讚賞。

我還注意到請求的 Content‑Type 標頭是 application/x‑www‑form‑urlencoded 而不是 text/ x‑gwt‑rpc 就像我設置的一樣。

這部分的HTML說:

<form target="FormPanel_app_2" method="post" action="/app/login" enctype="text/x‑gwt‑rpc">
    <!‑‑ ... ‑‑>
</form>

參考解法

方法 1:

In GWT, text/x‑gwt‑rpc is used when GWT RPC is used as the server communication mode. In your example, you are submitting a normal HTML form (which is unaware of text/x‑gwt‑rpc as it is not a standard content type).

There are 2 options:

  1. If you intend to use HTML form, you should be exposing a separate servlet to handle application/x‑www‑form‑urlencoded form submission.
  2. If you want to stick to GWT RPC, you can define some LoginService which captures username & password from fields and send the data to RPC servlet using GWT RPC semantics. (http://www.gwtproject.org/doc/latest/tutorial/RPC.html)

(by Stefan FalkMohit)

參考文件

  1. Content‑Type was 'application/x‑www‑form‑urlencoded'. Expected 'text/x‑gwt‑rpc' (CC BY‑SA 2.5/3.0/4.0)

#gwt #spring






相關問題

通過 GWT-RPC 發送持久的 JDO 實例 (Sending persisted JDO instances over GWT-RPC)

GWT:帶有 db 變量的屬性文件的安全位置 (GWT: Safe place for properties file with db variables)

paket khusus dalam toples eksternal GWT (specific packages in a external jar GWT)

在 gwt 框架中使用參數更改 url (Changing url with parameters in gwt framework)

通過 JavaScript 在標題或 HTML 中動態包含腳本元素 (Dynamically include script element in header or HTML by JavaScript)

Java如何在構造函數中將接口作為參數傳遞? (Java How do I pass interface as parameter in Constructor?)

如何更改 gwt 面板的內容? (How to change the content of a gwt panel?)

內容類型是“應用程序/x-www-form-urlencoded”。預期的“文本/x-gwt-rpc” (Content-Type was 'application/x-www-form-urlencoded'. Expected 'text/x-gwt-rpc')

如何從谷歌應用引擎調用我的應用網址 (How to call my app url from google app engine)

GXT NumberField 不可編輯 (GXT NumberField not editable)

在碼頭上部署 gwt Web 應用程序 (deploying gwt web application on jetty)

在 gwt 中使用 html5 畫布畫一個圓圈? (draw a circle using html5 canvas in gwt?)







留言討論