📄 login.java
字号:
package com.doone.fj1w.fjmgr.login;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.doone.data.DataTable;
import com.doone.fj1w.fjmgr.sysmgr.Tf_OrganiseCityRela;
import com.doone.util.FileLogger;
import com.doone.uurm.PasswordException;
import com.doone.uurm.Purview;
import com.doone.uurm.Sys_Online;
import com.doone.uurm.WebAuth;
import com.doone.web.Resource;
/**
* Created by IntelliJ IDEA. User: lizhx Date: 2005-7-19 Time: 8:49:54
* Email:lizx@doone.com.cn
*/
public class Login extends HttpServlet {
/**
* 生成唯一的serialVersionUID标识号。
*/
private static final long serialVersionUID = 1865547881860786027L;
static final private String CONTENT_TYPE = "text/html; charset=GBK";
public void init() throws ServletException {
}
public void doGet(HttpServletRequest httpRequest,
HttpServletResponse httpResponse) throws ServletException,
IOException {
FileLogger log = new FileLogger();
httpRequest.setCharacterEncoding("GBK");
httpResponse.setContentType(CONTENT_TYPE);
PrintWriter out = httpResponse.getWriter();
try {
// 工号全部只使用小写。
String sStaffCode = httpRequest.getParameter("STAFFCODE").toLowerCase().trim();
String sPasswd = httpRequest.getParameter("PASSWD").trim();
Purview purv = Purview.getInstance(httpRequest);
String sCltVID = Sys_Online.GenVID(9);
String sIP = httpRequest.getRemoteHost();
WebAuth auth = purv.Logon(sStaffCode, sPasswd, sCltVID, sIP);
// 加载城市信息。
DataTable dt = Tf_OrganiseCityRela.getCityListByStaff(auth
.getUserCode());
List list = new ArrayList();
for (int i = 0; i < dt.getRows().getCount(); i++) {
String[] citys = new String[2];
citys[0] = dt.getRow(i).getString("citycode");
citys[1] = dt.getRow(i).getString("cityname");
list.add(citys);
if (i == 0) {
auth.setCityCode(citys[0]);
auth.setCityName(citys[1]);
}
}
auth.setCitys(list);
// 加载岗位信息。
dt = Tf_OrganiseCityRela.getPostListByStaff(null, auth.getUserID());
list = new ArrayList();
if ( dt.getRows().getCount() > 0 ) {
String[] citys = new String[] {"", "无地区信息"};
auth.getCitys().add(0, citys);
auth.setCityCode(citys[0]);
auth.setCityName(citys[1]);
for ( int i=0; i<dt.getRows().getCount(); i++) {
String[] posts = new String[2];
posts[0] = dt.getRow(i).getString("ORGANISEID");
posts[1] = dt.getRow(i).getString("ORGANISENAME");
list.add(posts);
if (i == 0) {
auth.setCurrPostID(dt.getRow(i).getLong(
"ORGANISEID"));
}
}
}
else if ( auth.getCityCode() != null ){
dt = Tf_OrganiseCityRela.getPostListByStaff(auth.getCityCode(), auth.getUserID());
for ( int i=0; i<dt.getRows().getCount(); i++) {
String[] posts = new String[2];
posts[0] = dt.getRow(i).getString("ORGANISEID");
posts[1] = dt.getRow(i).getString("ORGANISENAME");
list.add(posts);
if (i == 0) {
auth.setCurrPostID(dt.getRow(i).getLong(
"ORGANISEID"));
}
}
}
if ( list.size() == 0 ) {
throw new RuntimeException("当前用户已经被禁用。");
}
auth.setPosts(list);
// 设置获取资源的Servlet为已经验证,以方便使用资源。
Resource.setAuthed(true);
login_success(out);
} catch (PasswordException e) {
login_failure(out);
} catch (RuntimeException e) {
log.warn(e.getMessage(), e);
login_failure(out);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
login_failure(out);
}
}
public void doPost(HttpServletRequest httpRequest,
HttpServletResponse httpResponse) throws ServletException,
IOException {
doGet(httpRequest, httpResponse);
}
public static String replace(String source, String oldString,
String newString) {
StringBuffer output = new StringBuffer();
int lengthOfsource = source.length(); // 源字符串长度
int lengthOfold = oldString.length(); // 老字符串长度
int posStart = 0; // 开始搜索位置
int pos; // 搜索到的老字符串的位置
// source.indexOf(oldString,posStart)检索某子串在字符串postStart以后第一次出现的位置,如果未找到就返回一个-1。
while ((pos = source.indexOf(oldString, posStart)) >= 0) { // 得到字符串的位置(eg:如果有<br>就执行,没有就跳出,不要处理。)
// 将以posStart起始以pos-1结束之间的内容拷贝到另一个字符串中。因为posStar从0开始的。
output.append(source.substring(posStart, pos)); // append方法将文本添加到当前StringBuffer对象内容的结尾。
output.append(newString); // 替换成新字符串
posStart = pos + lengthOfold; // 位置也变为找到了之后的位置,pos为得到第一次出现字符的位置,lengthold为字符的长度
}
if (posStart < lengthOfsource) {
// source.substring(posStart)以lengthOfsource开始的字符串拷贝到列一个字符串中
output.append(source.substring(posStart));
}
// 这个方法将其内容转换成一个可以被用于输出的字符串对象。它允许操作对应的文本用于输出或数据存储。
return output.toString();
}
public static String Replace(String source) {
source = replace(source, "<", "<");
source = replace(source, ">", ">");
source = replace(source, "\t", " ");
source = replace(source, "\r\n", "\n");
source = replace(source, "\n", "<br>");
source = replace(source, " ", " ");
source = replace(source, "'", "'");
source = replace(source, "\\", "/");
source = replace(source, "\"", """);
return source.toString();
}
public void login_failure(PrintWriter out) {
out
.print(""
+ "<html>\n"
+ "<head>\n"
+ "<title></title>\n"
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=GB2312\">\n"
+ "<script language=\"JavaScript\" type=\"text/JavaScript\">\n"
+ "<!--\n"
+ "function MM_goToURL() { //v3.0\n"
+ " var i, args=MM_goToURL.arguments; document.MM_returnValue = false;\n"
+ " for (i=0; i<(args.length-1); i+=2) eval(args[i]+\".location='\"+args[i+1]+\"'\");\n"
+ "}\n"
+ "//-->\n"
+ "</script>\n"
+ "</head>\n"
+ "<script language=\"JavaScript\" type=\"text/JavaScript\">\n"
+ "function redirect(URLStr) { location = URLStr; }\n"
+ "</script>\n"
+ "\n"
+ "<body onLoad=\"MM_goToURL('parent','/manager/view/login/login.jsp?error=2');return document.MM_returnValue\">\n"
+ "登录失败...\n" + "</body>\n" + "</html>");
}
public void login_success(PrintWriter out) {
out
.print(""
+ "<html>\n"
+ "<head>\n"
+ "<title></title>\n"
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=GB2312\">\n"
+ "<script language=\"JavaScript\" type=\"text/JavaScript\">\n"
+ "<!--\n"
+ "function MM_goToURL() { //v3.0\n"
+ " var i, args=MM_goToURL.arguments; document.MM_returnValue = false;\n"
+ " for (i=0; i<(args.length-1); i+=2) eval(args[i]+\".location='\"+args[i+1]+\"'\");\n"
+ "}\n"
+ "//-->\n"
+ "</script>\n"
+ "</head>\n"
+ "<script language=\"JavaScript\" type=\"text/JavaScript\">\n"
+ "function redirect(URLStr) { location = URLStr; }\n"
+ "</script>\n"
+ "\n"
+ "<body onLoad=\"MM_goToURL('parent','/manager/view/index.jsp');return document.MM_returnValue\">\n"
+ "登录中...\n" + "</body>\n" + "</html>");
}
// Clean up resources
public void destroy() {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -