📄 loginservlet.java
字号:
/**
* Copyright 2003-2005 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jdon.security.web;
import javax.servlet.http.*;
import java.io.IOException;
import javax.servlet.ServletException;
import com.jdon.util.RequestUtil;
import com.jdon.util.StringUtil;
import com.jdon.util.Debug;
/**
* please config Login.Module.Name in web.xml
*
* Login.Module.Name is the name in the jboss/login-config.xml
*
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Jdon.com Copyright (c) 2003</p>
* <p></p>
* @author banq
* @version 1.0
*/
public class LoginServlet extends HttpServlet {
private final static String module = LoginServlet.class.getName();
public final static String Login_Module = "SecurityRealm";
private String Login_Module_Name;
private String Login_Home_Uri;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String username = request.getParameter("j_username");
String password = request.getParameter("j_password");
Debug.logVerbose(username + " will login ... ", module);
//保存自动登陆 和密码
if (request.getParameter("rememberMe") != null) {
RequestUtil.setCookie(response, "rememberMe", "true", "/");
RequestUtil.setCookie(response, "username",
StringUtil.encodeString(username),
"/");
RequestUtil.setCookie(response, "password",
StringUtil.encodeString(password),
"/");
}
String j_req =
"j_security_check?j_username=" + RequestUtil.encodeURL(username)
+ "&j_password=" + RequestUtil.encodeURL(password);
response.sendRedirect(response.encodeRedirectURL(j_req));
}
public void init() throws ServletException {
Login_Module_Name = this.getInitParameter("Login.Module.Name");
if ( (Login_Module_Name == null) || (Login_Module_Name.equals("")))
Login_Module_Name = Login_Module;
Login_Home_Uri = this.getInitParameter("Login.Home.Uri");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -