package myPackage;
public class MyFormAuthenticator extends FormAuthenticator{
//code lies here
}
Web.xml文件
<web-app>
...
<servlet>
<servlet-name>myservlet</servlet-name>
<jsp-file>/securedfile.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/secured</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>SecuredBookSite</web-resource-name>
<url-pattern>/secured/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<description>Let only managers use this app</description>
<role-name>employee</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>employee</role-name>
</security-role>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error.jsp</form-error-page>
</form-login-config>
</login-config>
...
</web-app>
我读到context.xml文件应被编辑用于非默认用途。但是我不知道。我刚开始使用tomcat,所以我真的不知道要使用它。 您可以对FormAuthenticator的工作方式进行一些解释吗?
我尝试过这样
context.xml
<Context docBase="Form_Auth1">
<Valve className ="myPackage.MyFormAuthenticator"/>
</Context>
iam使用cmd编译Java类。 Tomcat版本:8.5 角色在Tomcat-users.xml中定义
请帮助
预先感谢