?? validate.java
字號:
package com.ata.shoping.servlet;
/*
* 用戶身份的驗證
* 若為管理員用戶登錄管理員頁面
* 若為用戶登錄用戶頁面
* 若所輸入的用戶名和密碼有錯,返回首頁
*/
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import com.projiect.shopping.sql.*;
@SuppressWarnings("serial")
public class Validate extends HttpServlet {
/**
* Constructor of the object.
*/
public Validate() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("gbk");
HttpSession session = request.getSession();
String userName = request.getParameter("username");
String password = request.getParameter("password");
PrintWriter out = response.getWriter();
// out.print(userName+" "+password);
UserInfo userinfo = new UserInfo();
userinfo.setUserName(userName);
userinfo.setPassword(password);
if(JdbcOperation.IsUserinfoExist(userinfo)){
session.setAttribute("enterUser", userinfo);
if(userName.equals("admin")){
//管理員用戶登錄
session.setAttribute("username", userName);
response.sendRedirect("/Shopping/Login.jsp");
}else{
//消費用戶登錄
session.setAttribute("username", userName);
response.sendRedirect("/Shopping/home.jsp");
}
}
else
{//登錄出錯
response.sendRedirect("/Shopping/index.jsp?err=errin");
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -