当将login.xhtml设置为我的主页时,它不起作用 [英] When set login.xhtml as my homepage it does not work
问题描述
当我将我的login.xhtml页面设置为web.xml作为欢迎文件时,它不起作用,我的意思是它显示的页面很好,但是当我按登录时没有任何反应,但是当我手动进入时到登录页面http://localhost:8080/fileuploadWithPreview/login.xhtml
的情况下,它运行完美,有什么主意吗?
when i set my login.xhtml page to be the web.xml to be the welcome file, it does not work, i mean it displays the page just fine but when i press log in nothing happens, but when i manually go to the log in page http://localhost:8080/fileuploadWithPreview/login.xhtml
it works perfectly, any ideas why this is ?
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>Upload Filter</filter-name>
<filter-class>richard.fileupload.UploadFilter</filter-class>
<init-param>
<param-name>sizeThreshold</param-name>
<param-value>1024</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Upload Filter</filter-name>
<url-pattern>/faces/upload/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/corejsf.taglib.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>LDAP</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/login-failed.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>user</role-name>
</security-role>
<security-constraint>
<!-- web resources that are protected -->
<web-resource-collection>
<web-resource-name>All Resources</web-resource-name>
<url-pattern>/*</url-pattern>
<!-- this is currently causing a 404 -->
<http-method>GETLIB</http-method>
<http-method>COPY</http-method>
<http-method>MOVE</http-method>
<http-method>DELETE</http-method>
<http-method>PROPFIND</http-method>
<http-method>GET</http-method>
<http-method>HEAD</http-method>
<http-method>PUT</http-method>
<http-method>MKCOL</http-method>
<http-method>PROPPATCH</http-method>
<http-method>LOCK</http-method>
<http-method>UNLOCK</http-method>
<http-method>VERSION-CONTROL</http-method>
<http-method>CHECKIN</http-method>
<http-method>CHECKOUT</http-method>
<http-method>UNCHECKOUT</http-method>
<http-method>REPORT</http-method>
<http-method>UPDATE</http-method>
<http-method>CANCELUPLOAD</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
</web-app>
好了,这样就可以了,正当我按下登录按钮时,它带我回到登录页面,但是它已经对用户进行了身份验证,如何在登录按钮上获取它,才能一次进入index.html页面已验证?
Ok so it is working, just when i press the login button it takes me back to the login page but it has already authenticated the user, how do i get it on the login button to go to the index.html page once authenticated ?
登录页面:
<div id="site_content">
<div id="content">
<h:body>
<form method="post" action="j_security_check">
<p>You need to log in to access protected information.</p>
<table>
<tr>
<td>User name:</td>
<td><input type="text" name="j_username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="j_password" /></td>
</tr>
</table>
<p><input type="submit" value="Login" />
<!--<h:commandButton value="This will reset all the data " type="button" > </h:commandButton> -->
<input type="reset" name="Login-reset" value="Reset" onclick="alert('This will reset all the data');" />
</p>
</form>
</h:body>
</div>
</div>
推荐答案
用<url-pattern>*.xhtml</url-pattern>
替换<url-pattern>/faces/*</url-pattern>
,并删除所有URL中的所有/faces/
路径.这样,一切都应该按预期工作.
Replace <url-pattern>/faces/*</url-pattern>
by <url-pattern>*.xhtml</url-pattern>
and get rid of all /faces/
paths in all your URLs. This way everything should work as expected.
说明:<welcome-file>
期望当前请求的文件夹(!)中的物理存在文件,该文件本应为index.xhtml
或login.xhtml
,而<form-login-page>
期望完整的URI应为/faces/login.xhtml
.当您将文件夹映射用于JSF时,这并不太好.因此,只需将其映射到*.xhtml
上,您就不必担心虚拟URL.
Explanation: the <welcome-file>
expects a physically existing file in the currently requested folder(!) which should have been index.xhtml
or login.xhtml
and the <form-login-page>
expects a fullworthy URI which should have been /faces/login.xhtml
. That don't mix quite well when you use a folder mapping for JSF. So just map it on *.xhtml
and you never need to worry about virtual URLs.
这篇关于当将login.xhtml设置为我的主页时,它不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!