In our FTP login will appear a picture of the prompt box, this feature can be configured to implement our files, without the need to write any code.
first, modify the role (add, delete)
Conf/tomcat-users.xml the role of Tomcat, by default admin, manager and other roles, if you want to add a custom role, you can use the form
<user username= "Xiazdong" password= "Xiazdong" roles= "user"/> form, we are now configured with a name of Xiazdong, password is xiazdong, the role is user users.
If you restart Tomcat, a <role rolename= "user"/> statement is automatically generated in Tomcat-users.xml.
II. Implementation of login verification
A write-like form is required in Web-inf/web.xml
<security-constraint>
<web-resource-collection>
<web-resource-name>RegisterUsers< Location of/web-resource-name> <url-pattern>/demo/security.jsp</url-pattern> <!--validated pages-->
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name> <!--validation role, do not write user name-->
</auth-constraint>
</security-constraint>
< login-config>
<auth-method>BASIC</auth-method> <!--key-->
<realm-name >registered users</realm-name>
</login-config>
<security-role>
< Role-name>user</role-name> <!--validation role, do not write user name-->
</security-role>
Restart Tomcat, you can write a security.jsp verification.
Enter the user name Xiazdong, the password is Xiazdong can log on to the Web page.
If the role is user, you can see the page.
<%@ page contenttype= "text/html" language= "java" pageencoding= "GB2312"%>