繁体   English   中英

如何修复tomcat HTTP状态403:访问被拒绝

[英]How to fix tomcat HTTP status 403 : access denied

我使用eclipse创建了一个简单的形式化tomcat,其中需要输入名称和密码。 但是,当我将用户名和密码放在文件tomcat-users.xml中时,我收到错误HTTP状态403,这意味着访问被拒绝。

我猜问题出在web.xml或server.xml中。 我知道该错误不在tomcat-users.xml中,因为我尝试了所有操作,但始终遇到相同的错误。

相对于我的TestServlet的文件web.xml中的脚本是:

<servlet>
        <servlet-name>TestServlet</servlet-name>
        <servlet-class>test.TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Wildcard means whole app requires authentication</web-resource-name>
            <url-pattern>/*</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>

    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.html</form-login-page>
            <form-error-page>/login-failed.html</form-error-page>
        </form-login-config>
    </login-config>

PS:当我输入错误的凭据时,我得到的页面login-failed.html,因此当我输入错误的凭据时一切正常。 PS:tomcat-users.xml文件中的代码是:

<tomcat-users>
<role rolename="manager"/>
<user username="admin" password="admin" roles="manager"/>
</tomcat-users>

有人可以帮我解决问题吗?

U解压缩它并尝试通过调用localhost:8080来访问它,并提供登录凭据,但无法正确登录。 意味着您无权访问该gui。因此,您必须手动编辑XML文件并修改此类脚本才能访问gui。 在那之后,我希望它一定会起作用

添加以下脚本

    <tomcat-users>
      <role rolename="manager-gui"/>
   <role rolename="manager-jmx"/>
   <role rolename="manager-status"/>
   <user username="admin" password="admin" 
     roles="manager-gui,manager-status"/>
    </tomcat-users>

    manager-gui — Access to the HTML interface.

在auth-constraint中,您已配置“ tomcat”角色。 您的tomcat-users.xml文件中缺少此角色。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM