gpt4 book ai didi

java - Http 状态 401 此请求需要 HTTP 身份验证 ()。在 tomcat 6

转载 作者:行者123 更新时间:2023-11-28 23:55:50 25 4
gpt4 key购买 nike

我开发了一个网络应用程序 enter image description here

如果我在 tomcat 6 中运行应用程序,它会要求输入用户名和密码但经过 3 次尝试后显示 enter image description hereweb.xml 文件是

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns: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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>LoginRemote</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>
<servlet>

<description></description>
<display-name>remoteSample</display-name>
<servlet-name>remoteSample</servlet-name>
<servlet-class>com.src.remoteSample</servlet-class>
</servlet>

<servlet-mapping>

<servlet-name>remoteSample</servlet-name>
<url-pattern>/remoteSample</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>Secure</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>


</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Authentication required</realm-name>
</login-config>
<security-role>
<role-name>*</role-name>
</security-role>
</web-app>

我想获取远程用户的用户名和密码,我应该怎么做?这是我的 servlet 代码

package com.src;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.tomcat.util.buf.Base64;

public class remoteSample extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public remoteSample() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

response.setContentType("text/html;charset=UTF-8");
System.out.println("login info:"+request.getRemoteUser());
System.out.println("Authentication type:"+request.getAuthType());

}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}

我应该更改服务器的 tomcat-server.xml 和 web.xml 中的某些内容吗?

最佳答案

检查您在服务器和远程用户中使用的域名是否与以下名称匹配。

<realm-name>Authentication required</realm-name>

请检查这个link有关异常的更多信息

关于java - Http 状态 401 此请求需要 HTTP 身份验证 ()。在 tomcat 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28359550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com