JSF代码片断整理

JSF代码片断整理

一、Action Controller的Action方法中手工获取请求信息
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest) context.getRequest();
String email = request.getParameter("form2:email");

二、保护/下面的jsp文件不被直接访问
在web.xml中加入:
<security-constraint>
<display-name>
    Prevent access to raw JSP pages that are for JSF pages.
</display-name>
<web-resource-collection>
    <web-resource-name>Raw-JSF-JSP-Pages</web-resource-name>
    <!-- Add url-pattern for EACH raw JSP page -->
    <url-pattern>/welcome.jsp</url-pattern>
    <url-pattern>/login.jsp</url-pattern>
    ......
</web-resource-collection>
<auth-constraint>
      <description>No roles, so no direct access</description>
</auth-constraint>
</security-constraint>

三、加载国际化资源文件
<f:view locale="#{facesContext.externalContext.request.locale}">
<f:loadBundle basename="messages" var="msgs"/>

/WEB-INF/classes目录下,放messages_cn.properties,message_en.properties.....

待续。。。

你可能感兴趣的:(JSF代码片断整理)