1

我需要在 wicket 应用程序中创建一个登录 Web 服务,并从 jQuery $.ajax() 函数中调用它。我找到了 wicketstuff-restannotations 并尝试了以下代码:

public static class DestinationUrl implements Serializable
{
  private String authorizedUrl;

  public String getAuthorizedUrl()
  {
    return authorizedUrl;
  }

  public void setAuthorizedUrl(String authorizedUrl)
  {
    this.authorizedUrl = authorizedUrl;
  }

}

public static class GsonLogonService extends GsonRestResource implements Serializable
{
  private AuthenticatedWebSession session;

  public AuthenticatedWebSession getSession()
  {
    return session;
  }

  public void setSession(AuthenticatedWebSession session)
  {
    this.session = session;
  }

  @MethodMapping(value = "/loginService", httpMethod = HttpMethod.POST)
  public DestinationUrl logonService(@RequestBody String username, @RequestBody String password)
  {
    DestinationUrl result = new DestinationUrl();
    if (session.signIn(username, password))
      result.setAuthorizedUrl(RequestCycle.get().getRequest().getOriginalUrl().toString());
    else
      result.setAuthorizedUrl("/");
    return result;
  }

}

但是我还应该做什么才能使该服务出现在 /logonService 或 /MyContext/logonService 下?使用 $.ajax() 或 $.get() 调用其中任何一个都会产生 404 ...

4

0 回答 0