日期:2014-05-16  浏览次数:20419 次

jsf 问题集锦 转
  1. 1.如何结束session? ??
  2. 你可以使用session的?invalidate方法?. ??
  3. 下面是一个从action方法中结束session的例子:?: ??
  4. public?String?logout()?{ ??
  5. ??FacesContext?fc?=?FacesContext.getCurrentInstance(); ??
  6. ??HttpSession?session?=?(HttpSession)?fc.getExternalContext().getSession(false); ??
  7. ??session.invalidate(); ??
  8. ??return?"login_page"; ??
  9. }? ??
  10. 下面的代码片段示例了如何在JSP页面中结束session: ??
  11. <%?session.invalidate();?%> ??
  12. <c:redirect?url="loginPage.jsf"?/> ??
  13. ??
  14. ??
  15. 2.如何在JSP页面中访问web.xml中的初始化参数? ??
  16. 你可以使用预定义的JSF?EL变量??initParam来访问: ??
  17. 例如,如果你有: ??
  18. <context-param> ??
  19. ?<param-name>productId</param-name> ??
  20. ?<param-value>2004Q4</param-value> ??
  21. </context-param> ??
  22. 你可以使用她?#{initParam['productId']}来访问?.例如: ??
  23. Product?Id:?<h:outputText?value="#{initParam['productId']}"/> ??
  24. ??
  25. ??
  26. 3.如何从java代码中访问web.xml?中的初始化参数? ??
  27. 你可以使用externalContext的?getInitParameter?方法得到他们.例如?如果你的参数如下: ??
  28. <context-param> ??
  29. ?<param-name>connectionString</param-name> ??
  30. ?<param-value>jdbc:oracle:thin:scott/tiger@cartman:1521:O901DB</param-value> ??
  31. </context-param> ??
  32. 你可以使用下面代码访问connectionString?: ??
  33. FacesContext?fc?=?FacesContext.getCurrentInstance();String?connection?=?fc.getExternalContext().getInitParameter("connectionString");? ??
  34. ??
  35. ??
  36. 4.如何从backing?bean中得到当前页面的URL? ??
  37. 你可以通过FacesContext得到一个Http?Request对象的引用,如下: ??
  38. FacesContext?fc?=?FacesContext.getCurrentInstance();HttpServletRequest?request?=?(HttpServletRequest)?fc.getExternalContext().getRequest();? ??
  39. 然后使用普通的request方法来得到路径信息.还可以使用另外一种方法: ??
  40. context.getViewRoot().getViewId(); ??
  41. 将返回你当前JSP(JSF?view?IDs?基本上只是JSP?path?names)页面的名字. ??
  42. ??
  43. ??
  44. 5.如何添加上下文路径到outputLink的URL中? ??
  45. 在当前的JSF实现中,当在outputLink?中定义的路径以'/'开始时,没有添加上下文路径到URL中,要弥补该问题请在URL中使用?#{facesContext.externalCon