App Engine

使用 Session

跟傳統 JSP 不同的是......
  • appengine-web.xml 內加上 
    <sessions-enabled>true</sessions-enabled>
  • 放進 session 的 class 必須 implement Serializable(deploy 後才會出事)
  • getAttribute() 取得 object 之後,如果有變動 object 內的 field,必須重新 setAttribute() 才有效果。(deploy 後才會出事)
GAE 有提供清除過期 session 的 servlet:com.google.apphosting.utils.servlet.SessionCleanupServlet,搭配 cron 使用就可以自動清除。

檢視 Local 端的資料

http://LOCAL_HOST/_ah/admin
有 index 的 field 才會出現

使用 EL

AppEngine 1.5.3

使用 GPE 自動產生的 web.xml 無法在 JSP 當中使用 EL,必須把下面這行砍掉
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
然後把 <web-app> 改成
<web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

JSP 的 request 物件

AppEngine 1.5.3

request.getLocalAddr() 會回傳 null。(deploy 後才會出事)
因為是不小心把 request.getRemoteAddr() 搞錯才發現的,沒打算解決 XDXD。

使用 Open-ID 登入

要記得到 Application Setting 將 Authentication Options 改成 Federated Login,否則會一直炸「java.lang.IllegalArgumentException: The requested URL was not allowed: http://foo.com」

deploy 失敗的障礙排除

    appcfg --application=APP_ID rollback PORJECT_PATH/war

如果是用 GPE,那 appcfg 應該會在 `ECLIPSE_PATH/plugins/com.google.appengine.eclipse.sdk*/appengine-java-sdk-*/bin` 底下。
子網頁 (2): GPE objectify
ċ
chatWithChannelAPI.rar
(1k)
Ps Monkey,
2011年9月28日 凌晨2:07
Comments