我尝试学习JSF。使用commandLink时,JSF使用Javascript-Code将其呈现为HTML:
<p><h:form><a jsfc="h:commandLink" action="#{user.logout}">Logout</a></h:form></p>
<p>
<form id="j_idt15" name="j_idt15" method="post" action="/smsalert/auth/welcome.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt15" value="j_idt15" />
<script type="text/javascript" src="/*/javax.faces.resource/jsf.js?ln=javax.faces"> </script>
<a href="#" onclick="mojarra.jsfcljs(document.getElementById('j_idt15'),{'j_idt15:j_idt16':'j_idt15:j_idt16'},'');return false">Log Out</a><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-4859709923894071294:-3975844660345501662" autocomplete="off" />
</form>
</p>
问题是生成的jsf.js(/ * / javax.faces.resource / jsf.js ...)的URL。我试图谷歌问题,但没有找到太多帮助..我怎么能解决这个问题?
通过单击Logout:
调用的方法public String logout() {
logged = false;
return "index";
}
编辑:
我明白了!错误是我的web.xml。我有
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
当我用
替换它时<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
它有效!