【问题标题】:Stripes, GAE: How to implement other methods handling (POST)Stripes,GAE:如何实现其他方法处理(POST)
【发布时间】:2010-12-07 13:23:26
【问题描述】:

不知道为什么这个(来自 SomeActionBean.java 的附加方法)在 Google 应用引擎上不起作用? Localy 一切运行完美。知道在哪里寻找解决方案吗?

 /**
 * @return Page to display, filled with correct data
 */
@DefaultHandler
public Resolution welcome() {
    Resolution fd = new ForwardResolution(VIEW);
    HttpServletRequest request = this.ctx.getRequest();
    if(request.getMethod() == "POST") { 
        String content = getRequestContent(request);
        updateData(content);
    }else if (request.getMethod() == "GET"){
        String ct = request.getContentType();
        if(("application/json").equals(ct))
            try {
                getNotesJson(); //fill returnJson global variable
                fd = new JSONResolution(returnJson);
                //TODO Spread to other entities
            } catch (JSONException e) {
                e.printStackTrace();
            }
    }
    return fd;
}

【问题讨论】:

  • 你得到什么错误?你可以发布堆栈跟踪吗?
  • 刚刚想通了。它是 if 和 == 比较中的问题。 Kdeveloper,感谢您的评论,如果您写答案,我会接受。

标签: json google-app-engine methods http-post stripes


【解决方案1】:

String 比较是错误的:

request.getMethod() == "POST"

Java 字符串不是原语,因此它们应该通过 equals 方法进行比较:

"POST".equals(request.getMethod())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多