tomcat web.xml常用配置

通过tomcat设置URL访问权限
有basic方式和login方式
basic使用tomcat-user.xml上面的用户和权限
login需要编写login.jsp和error.jsp

以下是basic的示例

<?xml version="1.0" encoding="utf-8" ?>
<web-app>
	<!--servlet配置-->
	<servlet>
		<servlet-name>helloworld</servlet-name>
		<servlet-class>SimpleHello</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>helloworld</servlet-name>
		<url-pattern>/hello</url-pattern>
	</servlet-mapping>
	
	<!--会话设置, 过期时间: 单位分钟-->
	<session-config>
		<session-timeout>1</session-timeout>
	</session-config>
	
	<!--目录访问权限设置, 对应下面的login-config元素-->
	<security-constraint>  
		<web-resource-collection>  
			<web-resource-name>Protected Area</web-resource-name>  
			<url-pattern>/debug/*</url-pattern>  
			<http-method>GET</http-method>  
			<http-method>POST</http-method>  
		</web-resource-collection>  
		<auth-constraint>  
			<role-name>tomcat</role-name>  
		</auth-constraint>  
	</security-constraint>  
	
	<!--目录访问权限设置, auth-method:basic对应tomcat-users.xml文件里的role-->
	<login-config>  
		<auth-method>BASIC</auth-method>  
		<realm-name>My Test</realm-name>  
	</login-config>  
	
	<security-role>  
		<role-name>tomcat</role-name>  
	</security-role> 

</web-app>

你可能感兴趣的:(tomcat)