posts - 495,  comments - 11,  trackbacks - 0
          Question: constant name="struts.action.extension" value="action"???? 問題
          Answer:這個是系統從struts.properties默認繼承這個配置,所以用的時候會自動加上.action
          The URL extension to use to determine if the request is meant for a Struts action
          用URL擴展名來確定是否這個請求是被用作Struts action,其實也就是設置 action的后綴,例如login.do的'do'字。
          s:form 的時候用

          Question:Struts2的xml的配置
          Answer:Struts2默認會讀取classpath下的struts-default.xml,struts-plugin.xml,struts.xml這三個文件。
          struts-plugin.xml的位置struts-plugin.xml會在你下載的plugin的jar包中,如struts2-spring-plugin-2.0.6.jar。

          Question:java.lang.NullPointerException 異常
          Answer:應該沒在web.xml有配置struts 2的filter,試下將以下列代碼加到web.xml的元素之間:
          好像需要Tomcat 5.5以上,5.0會有問題,諸如NullPointerExceptio之類的

          Question:Could not find or error in struts.properties
          java.lang.IllegalStateException: struts.properties missing
          問題解決:把struts.properties 放到classes下即可了

          Question:的action才與struts.xml中的Action名一樣,
          而 <form> 中的action應為你的Action的路徑的全名如/mypath/myaction.action;
          Answer:Action中的屬性值可以通過Javabean規范與請求是的參數綁定,
          所以等Form標志的name屬性必須與Action屬性名一致。

          Question:取得Servlet API中的一些對象,如request、response或session等,應該怎么做?
          Answer:com.opensymphony.xwork2.ActionContext,可以通過它的靜態方法getContext()獲取當前Action的上下文對象,
          非IOC:
          另外,org.apache.struts2.ServletActionContext作為輔助類(Helper Class),可以幫助您快捷地獲得這幾個對象,
          HttpServletRequest request = ServletActionContext.getRequest();
          HttpServletResponse response = ServletActionContext.getResponse();
          HttpSession session = request.getSession();
          IOC:
          import org.apache.struts2.interceptor.ServletRequestAware;
          import org.apache.struts2.interceptor.ServletResponseAware;
          import org.apache.struts2.interceptor.SessionAware;
          publicclass IoCServlet extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware {
          ???? private String message;
          ???? private HttpServletRequest request;
          ???? private HttpServletResponse response;
          }

          Question:表達式的問題,有${表達式}、帶有#的表達式(如上文中的#session.msg),還有%開始的表達式,
          這些好像都是取出里面的值,請問這些$、#、%開頭的表達式有什么不同?各自在什么情況下使用?
          Answer:OGNL中的${...}可以在定義Action的result時,傳遞變量,如/deleteBook.action?isbn=${isbn}。也可以在國際化時引用變量;
          #用于在頁面上引用ActionContext的值,也可以構造映射(Map)等,如#request.xxx;
          %{...}在標簽屬性中引用變量,如

          Question:如何得到cookies
          Answer:先在Action中拿到HttpServletRequest的對象(請參考《Struts 2.0的Action講解》),然后調用request.getCookies()。

          Question:
          頁面就可以直接獲取${message},請問這默認是request級別的嗎?
          如果是session級別的,是不是要在取得session后
          在代碼中明確寫入,session.setAttribute(xx.xxxx)
          Answer:這些值是放在ActionContext中的,所以不是request或session等

          轉載資料 from http://www.aygfsteel.com/max

          posted on 2007-09-24 14:40 jadmin 閱讀(134) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 吉林市| 延吉市| 蒙自县| 蒙山县| 宜川县| 瓮安县| 揭西县| 和顺县| 安福县| 南丹县| 宜川县| 延长县| 甘谷县| 天水市| 塔城市| 大同市| 吉木萨尔县| 光泽县| 乡宁县| 云龙县| 浦县| 磐石市| 雷山县| 宜都市| 友谊县| 新竹县| 利津县| 昌都县| 宝山区| 桂林市| 安新县| 桃源县| 武平县| 北碚区| 蛟河市| 普兰店市| 云林县| 寻甸| 共和县| 攀枝花市| 宁南县|