📄 loginservlet.java
字号:
resp.setContentType("text/html; charset=iso-8859-1"); PrintWriter out = resp.getWriter(); out.println("<pre>"); e.printStackTrace(out); out.println("</pre>"); } } /** * User has submitted the Login form via a POST. * Create a new authorization entry for the * specified <code>protocol://user:password@site:port/realm</code> * and redirect to continue the user's original search. */ private void doLogin(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { Map ht = req.getParameterMap(); String[] protocol = (String[])ht.get("protocol"); String[] host = (String[])ht.get("host"); String[] port = (String[])ht.get("port"); String[] realm = (String[])ht.get("realm"); String[] username = (String[])ht.get("username"); String[] password = (String[])ht.get("password"); String[] col = (String[])ht.get("searchable"); String[] othersites = (String[])ht.get("othersites"); if (protocol!=null && host!=null && port!=null && realm!=null && username!=null && password!=null && col!=null) { try { addAuthorization(req,col[0],protocol[0],host[0],Integer.parseInt(port[0]), realm[0],username[0].trim(),password[0].trim(), othersites!=null); } catch (MalformedURLException e) { throw new ServletException(e.getLocalizedMessage(),e); } } StringBuffer sb = new StringBuffer(req.getRequestURI()); sb.append('?'); Iterator it = ht.entrySet().iterator(); boolean first = true; while (it.hasNext()) { Map.Entry entry = (Map.Entry)it.next(); String key = (String)entry.getKey(); String[] values = (String[])entry.getValue(); if (key.equals("login")) continue; if (key.equals("protocol")) continue; if (key.equals("host")) continue; if (key.equals("port")) continue; if (key.equals("realm")) continue; if (key.equals("username")) continue; if (key.equals("password")) continue; if (key.equals("searchable")) continue; if (key.equals("othersites")) continue; for (int i=0; i<values.length; i++) { String value = values[i]; if (first) first = false; else sb.append('&'); sb.append(encode_URL(key)); sb.append('='); sb.append(encode_URL(value)); } } resp.sendRedirect(sb.toString()); } /** * User has given us new authorization information. Add it * to the guard's information. * We don't know if this information is correct, so we must * empty the cache of any previously authorized results * (and previous not-authorized results). * <p> * If the user said to allow this user:password pair to be * guessed, add it to the guess list. */ private void addAuthorization(HttpServletRequest req, String col, String protocol, String host, int port, String realm, String username, String password, boolean othersites) throws MalformedURLException { HttpSession session = req.getSession(true); AccessGuard guard = (AccessGuard) session.getAttribute(GUARD_ATTRIBUTE); if (guard==null) return; guard.addAuthorization(protocol,host,port,realm,username,password); String userpass = username+":"+password; if (othersites) { Set guesses = (Set)session.getAttribute(GUESSES_ATTRIBUTE); guesses.add(userpass); } Map logins = (Map)session.getAttribute(LOGINS_ATTRIBUTE); URL authURL = new URL(protocol,host,port,realm); logins.put(authURL,userpass); // Clear out any empty logins. Iterator it = logins.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry)it.next(); if (":".equals(entry.getValue())) it.remove(); } // Since we have a new login, we no longer know which sites // will continue to have non-viewable results. Set filteredSites = (Set)session.getAttribute(FILTERED_SITES_ATTRIBUTE); filteredSites.clear(); } // Translations of messages that are specific to LoginServlet static { la_textMap_map_init(new String[] { "Password-protected results from", "da", "Password-protected results from", "de", "Password-protected results from", "en", "Password-protected results from", "es", "Password-protected results from", "fi", "Password-protected results from", "fr", "Password-protected results from", "it", "Password-protected results from", "ja", "Password-protected results from", "ko", "Password-protected results from", "nl", "Password-protected results from", "no", "Password-protected results from", "pt", "Password-protected results from", "sv", "Password-protected results from", "zh_cn", "Password-protected results from", "zh_tw", "Password-protected results from", }); la_textMap_map_init(new String[] { "are available.", "da", "are available.", "de", "are available.", "en", "are available.", "es", "are available.", "fi", "are available.", "fr", "are available.", "it", "are available.", "ja", "are available.", "ko", "are available.", "nl", "are available.", "no", "are available.", "pt", "are available.", "sv", "are available.", "zh_cn", "are available.", "zh_tw", "are available.", }); la_textMap_map_init(new String[] { "Login", "da", "Login", "de", "Login", "en", "Login", "es", "Login", "fi", "Login", "fr", "Login", "it", "Login", "ja", "Login", "ko", "Login", "nl", "Login", "no", "Login", "pt", "Login", "sv", "Login", "zh_cn", "Login", "zh_tw", "Login", }); la_textMap_map_init(new String[] { "to include them.", "da", "to include them.", "de", "to include them.", "en", "to include them.", "es", "to include them.", "fi", "to include them.", "fr", "to include them.", "it", "to include them.", "ja", "to include them.", "ko", "to include them.", "nl", "to include them.", "no", "to include them.", "pt", "to include them.", "sv", "to include them.", "zh_cn", "to include them.", "zh_tw", "to include them.", }); la_textMap_map_init(new String[] { "to the realm", "da", "to the realm", "de", "to the realm", "en", "to the realm", "es", "to the realm", "fi", "to the realm", "fr", "to the realm", "it", "to the realm", "ja", "to the realm", "ko", "to the realm", "nl", "to the realm", "no", "to the realm", "pt", "to the realm", "sv", "to the realm", "zh_cn", "to the realm", "zh_tw", "to the realm", }); la_textMap_map_init(new String[] { "Site", "da", "Site", "de", "Site", "en", "Site", "es", "P\u00E1gina", "fi", "Websivut", "fr", "Site", "it", "Sito", "ja", "\u30B5\u30A4\u30C8", "ko", "\uC0AC\uC774\uD2B8", "nl", "Site", "no", "Nettsted", "pt", "Site", "sv", "Site", "zh_cn", "\u7F51\u7AD9", "zh_tw", "\u7DB2\u7AD9", }); la_textMap_map_init(new String[] { "Realm", "da", "Rige", "de", "Bereich", "en", "Realm", "es", "\u00C1mbito", "fi", "Alue", "fr", "Etendue", "it", "Regione", "ja", "\u9818\u57DF", "ko", "\uC601\uC5ED", "nl", "Realm", "no", "Omr\u00E5de", "pt", "Dom\u00EDnio", "sv", "Sf\u00E4r", "zh_cn", "\u8303\u56F4", "zh_tw", "\u7BC4\u570D", }); la_textMap_map_init(new String[] { "Username", "da", "Brugernavn", "de", "Benutzername", "en", "Username", "es", "Nombre de usuario", "fi", "K\u00E4ytt\u00E4j\u00E4tunnus", "fr", "Nom d'utilisateur", "it", "Nomeutente", "ja", "\u30E6\u30FC\u30B6\u30FC\u540D", "ko", "\uC0AC\uC6A9\uC790 \uC774\uB984", "nl", "Gebruikersnaam", "no", "Brukernavn", "pt", "Nome do usu\u00E1rio", "sv", "Anv\u00E4ndarnamn", "zh_cn", "\u7528\u6237\u540D\u79F0", "zh_tw", "\u4F7F\u7528\u8005\u540D\u7A31", }); la_textMap_map_init(new String[] { "Password", "da", "Adgangskode", "de", "Passwort", "en", "Password", "es", "Contrase\u00F1a", "fi", "Salasana", "fr", "Mot de passe", "it", "Password", "ja", "\u30D1\u30B9\u30EF\u30FC\u30C9", "ko", "\uC554\uD638", "nl", "Wachtwoord", "no", "Passord", "pt", "Senha", "sv", "L\u00F6senord", "zh_cn", "\u5BC6\u7801", "zh_tw", "\u5BC6\u78BC", }); la_textMap_map_init(new String[] { "Automatically try to use this password for other sites, too.", "da", "Pr\u00F8v ogs\u00E5 automatisk at anvende dette password til andre sites", "de", "Dieses Passwort automatisch auch f\u00FCr andere Sites verwenden.", "en", "Automatically try to use this password for other sites, too.", "es", "Intentar usar autom\u00E1ticamente esta contrase\u00F1a tambi\u00E9n para otras p\u00E1ginas.", "fi", "Yritt\u00E4\u00E4 k\u00E4ytt\u00E4\u00E4 t\u00E4t\u00E4 salasanaa muillakin sivuilla.", "fr", "Essayez d'utiliser ce mot de passe pour d'autres sites.", "it", "Prova automaticamente a usare questa password anche per altri siti.", "ja", "\u307B\u304B\u306E\u30B5\u30A4\u30C8\u3067\u3082\u81EA\u52D5\u7684\u306B\u3053\u306E\u30D1\u30B9\u30EF\u30FC\u30C9\u3092\u4F7F\u7528", "ko", "\uB2E4\uB978 \uC0AC\uC774\uD2B8\uC5D0\uC11C \uC790\uB3D9\uC73C\uB85C \uC774 \uC554\uD638\uB97C \uC0AC\uC6A9\uD569\uB2C8\uB2E4.", "nl", "Probeer dit wachtwoord ook automatisch voor andere sites te gebruiken.", "no", "Pr\u00F8v automatisk \u00E5 bruke dette passordet for andre steder \u00F2g.", "pt", "Tamb\u00E9m tenta utilizar automaticamente esta senha para outros sites.", "sv", "F\u00F6rs\u00F6ka anv\u00E4nda detta l\u00F6senord automatiskt ocks\u00E5 f\u00F6r andra siter.", "zh_cn", "\u4E5F\u8BD5\u8457\u81EA\u52A8\u7528\u8FD9\u4E2A\u5BC6\u7801\u6765\u767B\u5F55\u5176\u5B83\u7684\u7F51\u7AD9\u3002", "zh_tw", "\u4E5F\u8A66\u8457\u81EA\u52D5\u4F7F\u7528\u6B64\u5BC6\u78BC\u4F86\u767B\u5165\u5176\u4ED6\u7DB2\u7AD9\u3002", }); };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -