【发布时间】:2013-11-19 20:33:47
【问题描述】:
所以我有一个 JSF 应用程序。如果我提交表单,刷新页面时会重新提交。我当然不想那样。
索引.xhtml:
[...]
<h:form >
<h:outputText value="Form"/><br/>
<h:inputText label="first" value="#{example.newExample.firstWord}" autocomplete="off"></h:inputText>
<h:commandButton value="click" actionListener="#{example.NewExample()}">
</h:commandButton>
</h:form>
[...]
运行的方法:
public void NewExample(){
pfDB.InsertNewExample(NewExample);
NewExample.setFirstWord(null);
NewExample.setSecondWord(null);
}
所以每次我在提交表单后刷新 index.xhtml 时,都会运行 NewExample()。
【问题讨论】:
-
那么,你的意思是 NewExample() 被调用了两次? (另外,请记住,在 java 中,约定是方法的第一个字母应该小写)
-
不,如果我在提交表单后手动刷新页面,则会调用它
-
那是因为刷新页面时再次提交了POST请求。您的网络浏览器可能会提醒您数据将再次发送并要求您确认。