Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 内容类型为';application/x-www-form-urlencoded';。预期';text/x-gwt-rpc';_Spring_Gwt - Fatal编程技术网

Spring 内容类型为';application/x-www-form-urlencoded';。预期';text/x-gwt-rpc';

Spring 内容类型为';application/x-www-form-urlencoded';。预期';text/x-gwt-rpc';,spring,gwt,Spring,Gwt,我正在尝试将Spring安全性与GWT结合使用,但我遇到了一个又一个问题,因为似乎没有什么事情能像它实际应该做的那样工作。目前,我正在尝试将所有内容连接到我的自定义登录页面。为此,我有一个FormPanel,初始化如下: public LoginViewImpl() { initWidget(uiBinder.createAndBindUi(this)); this.frmLogin.setMethod(FormPanel.METHOD_POST); this.frmL

我正在尝试将Spring安全性与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)
    ...
我不知道如何避免这种情况。感谢您的帮助

我还注意到请求的
内容类型
头是
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>

在GWT中,当GWT rpc用作服务器通信模式时,将使用
text/x-GWT-rpc
。在您的示例中,您正在提交一个普通的HTML表单(它不知道text/x-gwt-rpc,因为它不是标准的内容类型)

有两种选择:

  • 如果您打算使用HTML表单,那么应该公开一个单独的servlet来处理application/x-www-form-urlencoded表单提交
  • 如果您想坚持使用GWT RPC,可以定义一些LoginService,它从字段中捕获用户名和密码,并使用GWT RPC语义将数据发送到RPC servlet。()

  • 使用RequestBuilder

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,URL.encode(url));
    builder.setHeader("Content-type", "text/x-gwt-rpc");
    

    你好很抱歉反应太晚!我当然想在这里使用更简单、更直接的解决方案。我只需要这种对spring安全登录操作的调用,别的什么都不需要。但是这里哪一个比较容易呢?