I think they set proxy.
解决方案 »
- 一个关于图片点击后生成列表的问题
- 在javacript内怎么给jsp代码中string变量赋值
- 求一超难的正则替换方法!
- 客户端动态生成的控件,怎样在服务器端获得值?
- [高分求助] 求一套较复杂的页面操控程序,参与讨论的内容有借鉴意义,则都有分数相赠,谢谢。
- eclipce3.4为什么安装spket不能使用呢?
- 如何获得js的版本?
- 在location.href中写入参数
- 关于hignchars的图片文件的导出问题
- 想请教一个问题:用户填完表以后,可以下载下来,这些需要前端做啥?
- 130分 不要白不要啊~!问题太简单,要不就送上 500 分了。本人送分一向很慷慨呀。
- 怎么得到鼠标或IE在桌面上的座标
只要在Header 里加"WWW-Authenticate", "BASIC realm=basicauth servlet"这句就会弹出输入用户和密码的对话框。import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import sun.misc.*; // for Base64Decoder methodpublic class basicauth extends HttpServlet{
Hashtable users = new Hashtable(); // user:password list public void init(ServletConfig config) throws ServletException {
super.init(config);
users.put("billgates:imrich", "allowed"); // for testing purpose...
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
PrintWriter out = response.getWriter();
String auth = request.getHeader("Authorization"); // user name: BASE64 encoded
if(allowUser(auth)){
out.println("ok youre in!");
}
else{
response.setHeader("WWW-Authenticate", "BASIC realm=\"basicauth servlet\"");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
response.sendError(response.SC_UNAUTHORIZED); // HTTP 401
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
doGet(request, response);
} protected boolean allowUser(String auth) throws IOException{
if(auth == null){
return false;
}
if(!auth.toUpperCase().startsWith("BASIC ")){
return false;
}
String userPwdEncoded = auth.substring(6); // removes 'BASIC '
BASE64Decoder decoder = new BASE64Decoder();
String userPwdDecoded = new String(decoder.decodeBuffer(userPwdEncoded));
return "allowed".equals(users.get(userPwdDecoded))
}
}
what's different with setHeader and the meta tag.<meta http-equiv="WWW-Authenticate" content="BASIC realm='basicauth servlet'">
如果你的机子安装了IIS,那么把XXX。HTM文件设一下密码(很简单的,傻瓜都会),接着就会有这种效果了!!