我正在尝试为使用 Tomcat 部署的 Web 应用程序实现一个简单的基于表单的登录。 loginPage.html 具有 j_username
和 j_password
作为字段,表单方法是 j_security_check
,如指定的那样。/Actions 是一个目录,包含我所有的 html 和 jsp 文件,以及 css 和 js 文件,所有 servlet 映射的格式都是/Actions/servletName.do。唯一不在操作中的页面是 index.html 和 loginPage 以及 loginError。
现在,主页是 index.html。其中有一个指向 Actions/home.html 的超链接。我想要的是该超链接首先重定向到 loginPage.html,然后当用户登录时它将转到 home.html。我的理解是,由于 home.html 是受限资源,因此这应该自动发生。然而,相反,我没有被重定向到登录页面,浏览器显示一个错误,说它无法连接到该页面;顶部的 URL 是 https://localhost:8443/myProject/Actions/home.html和 https://localhost:8443/myProject/index.html .
我看过几个教程,但它们都没有指定完整的示例,包括文件位置。帮助将不胜感激。哦,是的,如果有人想知道,我确实相应地更新了 tomcat-users.xml 文件。
<welcome-file-list>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
<security-role><role-name>Admin</role-name></security-role>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/loginPage.html</form-login-page>
<form-error-page>/loginError.html</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>AllResources</web-resource-name>
<url-pattern>/Actions/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
最佳答案
您需要 configure Tomcat to use SSL首先,每当你想使用 HTTPS .否则你必须删除 <transport-guarantee>CONFIDENTIAL</transport-guarantee>
输入并修复 HTML/JSP 文件中的所有链接以指向 http://
而不是 https://
.
关于security - 基于 HTTPS 的表单登录失败,浏览器错误无法连接服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7005760/