jsp-安全

本文介绍了JSP在Tomcat服务器中的安全配置,包括在tomcat-users.xml中设置用户权限,以及在web.xml中配置认证机制如BASIC, FORM等,定义登录页面和错误页面,以及设定资源访问的安全约束和角色限制。" 107734380,9201317,深入理解Python模块与实战,"['Python编程', '模块化', '程序设计', '复用代码', '实战教程']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.在Tomat服务器中的Servers中的tomcat-users.xml文件中的tomcat-users节点下进行用户名和密码的配置
在这里插入图片描述

2.在web工程中的web.xml文件中配置一些必要结点
注释:
(1)首页为index.jsp
(2)login-config:定义认证机制
auth-method:指定认证机制(BASIC,FORM,DIGEST,CLIENT-CERT)
form-login-config:定义登录页和错误页
(3)web-resource-collection:指定安全约束应用的资源集合
auth-constraint:指定可访问受保护资源的角色
(4)security-role:指定用于安全约束中的安全角色的声明

<?xml version="1.0" encoding="UTF-8"?>

-<web-app version="2.5" id="WebApp_ID" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<display-name>09-03</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>


-<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>


-<security-constraint>


-<web-resource-collection>

<web-resource-name>form</web-resource-name>

<url-pattern>/form.jsp</url-pattern>

</web-resource-collection>


-<auth-constraint>

<role-name>tomcat</role-name>

<role-name>admin</role-name>

</auth-constraint>

</security-constraint>


-<security-role>

<role-name>tomcat</role-name>

</security-role>


-<security-role>

<role-name>admin</role-name>

</security-role>

</web-app>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值