?? servletlogin.java
字號(hào):
package myshop.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
/**
* 處理用戶登錄的認(rèn)證和根據(jù)認(rèn)證結(jié)果重新定向用戶
*/
public class ServletLogin extends HttpServlet {
// 僅處理 HTTP Get 請(qǐng)求
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
process(request, response);
}
// 僅處理 HTTP Post 請(qǐng)求
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
process(request, response);
}
// 統(tǒng)一處理 Get 和 Post 方式請(qǐng)求
private void process(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String username = request.getParameter("username"); //獲得提交用戶名參數(shù)的值
String password = request.getParameter("password"); //獲得提交密碼參數(shù)的值
if(username !=null && password!=null && //用戶名密碼都不能為空
"admin".equals(username) && //用戶名是“admin”
"111111".equals(password)) { //密碼是“111111”
response.sendRedirect("/maintain/main.jsp"); //重訂向用戶到功能頁(yè)面
return; //結(jié)束判定流程
} else {
response.sendRedirect("/maintain/index.jsp"); //重訂向用戶到登陸頁(yè)面
return; //結(jié)束判定流程
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -