Forms GET请求输入字段中的旧值
我在文件loginform.xhtml中得到了这个JSF表单:Forms GET请求输入字段中的旧值,forms,jsf,Forms,Jsf,我在文件loginform.xhtml中得到了这个JSF表单: <h:form> <h:panelGrid columns="3" styleClass="components" cellpadding="5px"> <h:outputText value="#{msg['login.username']}"/> <h:inputText id="username" value="#{
<h:form>
<h:panelGrid columns="3" styleClass="components" cellpadding="5px">
<h:outputText value="#{msg['login.username']}"/>
<h:inputText id="username" value="#{userManager.loginUser.username}" required="true"/>
<h:message styleClass="error" for="username"/>
<h:outputText value="#{msg['login.password']}"/>
<h:inputSecret id="password" value="#{userManager.loginUser.password}"
required="true"/>
<h:message styleClass="error" for="password"/>
<h:commandButton value="#{msg['login.confirm']}"
action="#{userManager.doLogin}"/>
</h:panelGrid>
</h:form>
}
这里是我的问题:如果我键入一个对loginform.xhtml的GET请求(在我的例子中:http://localhost:8080/Impetus-web/loginform.xhtml
),表单由旧值填充!更正确的值-这对系统的安全性非常不利:-)。如果我通过h:link标签导航到此页面,也会发生同样的情况。只有当我通过POST请求(通过commandButton f.e.)跳转到页面时,它才能正常工作
这是怎么可能的?JSF没有做到这一点(作为证据,查看生成的HTML输出)。网络浏览器就是这样做的。此功能称为“自动填充”/“自动完成”。只需将autocomplete=“off”
添加到各个输入组件中,告诉它不要这样做
<h:inputText ... autocomplete="off" />
<h:inputSecret ... autocomplete="off" />
可能您的
UserManager
bean的范围不正确。它是会话范围吗?是的,它是会话范围。我应该是的,不是吗?如果你让它成为@SessionScoped
,它取决于当前的HTTP会话,这使得它依赖于。只需将其更改为@ViewScoped
或@RequestScoped
,具体取决于您是否希望保留视图状态。是否浏览器只是存储了这些值,因为您保存了它们?这只是浏览器的问题?当您进入应用程序时,必须选择“不记住您当前的凭据…”。。。
<h:inputText ... autocomplete="off" />
<h:inputSecret ... autocomplete="off" />
<h:form ... autocomplete="off">