【问题标题】:security in Jsf2 guessing and modifying url should not be allowed不应允许 Jsf2 中的安全性猜测和修改 url
【发布时间】:2013-07-24 10:57:37
【问题描述】:

我有一个应用程序正在运行。我有一个页面addstudent.xhtml页面,用户在其中添加学生详细信息。当用户完成添加并提交后,他将被重定向到displaystudent.xhtml页面。

我的问题是当用户直接在浏览器上输入 本地主机:8081/学生/displaystudent.xhtml。页面显示为空白值。这不应该发生。即使他在浏览器上键入,我如何防止这种情况发生。

addstudent.xhtml displaystudent.xhtml 页面的两个文件都在 web-inf 文件夹中。我正在使用 Jsf2,primefaces 3.5

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    使displaystudent.xhtml 成为一个包含文件,根据学生是否成功添加,您有条件地在addstudent.xhtml 中呈现。

    例如,假设标准 JSF:

    <h:panelGroup id="addStudent" layout="block">
        <h:form rendered="#{empty bean.student.id}">
            <h2>Add student</h2>
            <h:inputText value="#{bean.student.name}" />
            ...
            <h:commandButton value="Add" action="#{bean.add}">
                <f:ajax execute="@form" render=":addStudent" />
            </h:commandButton>
        </h:form>
    
        <h:panelGroup layout="block" rendered="#{not empty bean.student.id}">
            <h2>Added student</h2>
            <dl>
                <dt>Student name</dt><dd>#{bean.student.name}</dd>
            </dl>
        </h:panelGroup>
    </h:panelGroup>
    

    (简化;你当然可以将添加学生拆分为&lt;ui:include src="/WEB-INF/displaystudent.xhtml"&gt; 等等)

    add() 方法应返回voidnull 的按钮重新呈现&lt;h:panelGroup id="addStudent"&gt;。如果学生被成功添加到数据库中,那么它应该有一个非空的 ID。这将导致表单被隐藏并显示结果面板。

    另见:

    【讨论】:

      猜你喜欢
      • 2011-05-26
      • 2012-10-12
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 2019-06-13
      • 2011-05-20
      • 2021-06-19
      • 2021-07-30
      相关资源
      最近更新 更多