我们访问tomcat服务器的时候如果试图访问Tomcat Manager就会发现浏览器弹出一个登陆对话框,和我们平常的网页对话框不同,而且查看页面的时候查不到生成这个对话框的代码,禁止脚本也毫无作用。手头的资料对这个东西没有任何介绍,它到底是怎么弹出来的呢?
用jmeter创建一个http request的sampler,再建一个view result tree的lisenter来看看服务器返回了些什么污七八糟的:
HTTP response headers:
HTTP/1.1 401 Unauthorized
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 08:00:00 CST
WWW-Authenticate: Basic realm="Tomcat Manager Application"
Content-Type: text/html;charset=utf-8
Content-Length: 954
Date: Thu, 30 Jun 2005 09:27:26 GMT
Server: Apache-Coyote/1.1
嘿嘿,原来是一个带WWW-Authenticate的401错误啊。自己写个JSP模拟一下看看怎么样:
<%
response.addHeader("WWW-Authenticate","Basic realm=\"Tomcat Manager Application\"");
response.sendError(401,"Unauthorized");
%>
果然,一个一模一样的登陆窗口跳出来了。不过身份验证的具体过程要怎么做呢?google了一下,果然看到好东西了: http://www.chinadata.cn/showContent.asp?projectID=2083
按照说明构造了一个jsp文件:
<%
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
boolean authenticated = false;
String authorization = request.getHeader("authorization");
System.out.println("authorization:" authorization);
if (authorization != null)
{
if (authorization.startsWith("Basic
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!



