?? loginservlet.java
字號:
/*
* 創(chuàng)建日期 2005-8-28
*
* TODO 要更改此生成的文件的模板,請轉至
* 窗口 - 首選項 - Java - 代碼樣式 - 代碼模板
*/
package com.publish.jxc.charpter9;
import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Administrator
*
* TODO 要更改此生成的類型注釋的模板,請轉至
* 窗口 - 首選項 - Java - 代碼樣式 - 代碼模板
*/
public class LoginServlet extends HttpServlet {
private UserXMLAction users;
// private static final String USER_XML_FILE = "data\\users.xml";
public void init(ServletConfig arg0) throws ServletException {
// TODO 自動生成方法存根
super.init(arg0);
users = new UserXMLAction();
String path = arg0.getServletContext().getRealPath("/");
users.readXMLFile(path + Utility.Users_XML_File);
}
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
// TODO 自動生成方法存根
//super.doGet(arg0, arg1);
doPost(arg0, arg1);
}
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
// TODO 自動生成方法存根
UserXMLModel user = users.getUser(arg0.getParameter("name"), arg0.getParameter("password"));
RequestDispatcher rd = null;
if (user != null)
{
arg0.getSession().setAttribute("user", user);
if (user.getRoles().equals("admin"))
{
rd = arg0.getRequestDispatcher(arg1.encodeURL("pages/admin/index.jsp"));
rd.forward(arg0, arg1);
}
else
{
rd = arg0.getRequestDispatcher(arg1.encodeURL("pages/index.jsp"));
rd.forward(arg0, arg1);
}
}
else
{
arg1.setContentType("text/html");
arg1.setCharacterEncoding("gb2312");
PrintWriter out = arg1.getWriter();
out.print(Utility.outPrintPage("用戶名或者密碼錯誤!", "index.jsp"));
}
//super.doPost(arg0, arg1);
}
protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
// TODO 自動生成方法存根
super.service(arg0, arg1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -