设置 tomcat-user.xml


<?xmlversion='1.0'encoding='utf-8'?><tomcat-users><rolerolename="yy_role"/><userusername="yyadmin"password="yyadmin"roles="yy_role"/></tomcat-users>


自己的工程下设置web.xml


<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID"version="2.5"><display-name>app</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><security-constraint><web-resource-collection><web-resource-name>forcelogin</web-resource-name><!--Definethecontext-relativeURL(s)tobeprotected--><url-pattern>/*</url-pattern><!--Ifyoulisthttpmethods,onlythosemethodsareprotected--></web-resource-collection><auth-constraint><!--Anyonewithoneofthelistedrolesmayaccessthisarea--><role-name>yy_role</role-name></auth-constraint></security-constraint><login-config><auth-method>BASIC</auth-method><realm-name>forcelogin</realm-name></login-config><!--Securityrolesreferencedbythiswebapplication--><security-role><role-name>yy_role</role-name></security-role></web-app>


测试:要加密的项目


测试:确认不影响网站其他项目