⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.java

📁 《J2EE企业级应用开发》一书的配套源代码
💻 JAVA
字号:
package com.j2eeapp.cdstore.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.j2eeapp.cdstore.bean.ShoppingSession;

public class Login extends HttpServlet
{
    
     private static final String CONTENT_TYPE = "text/html";
    /**
     * @J2EE_METHOD  --  doGet
     * Called by the server (via the service method) to allow a servlet to handle a GET request.
     * The servlet container must write the headers before committing the response, because
     * in HTTP the headers must be sent before the response body. The GET method should
     * be safe and idempotent. If the request is incorrectly formatted, doGet returns an
     * HTTP 'Bad Request' message.
     * @throws javax.servlet.ServletException
     * @throws java.io.IOException
     */
    public void doGet    (HttpServletRequest request, HttpServletResponse response) 
                throws ServletException, IOException 
    {
    	String username = request.getParameter("username");
        String password = request.getParameter("password");
        ShoppingSession shoppingSession = (ShoppingSession) request.getSession().getAttribute("shoppingSession");
	    try {
	      shoppingSession.login(username, password);
	    }
	    catch (Exception ex) {
	      ex.printStackTrace();
	    }
	    RequestDispatcher d = request.getRequestDispatcher("welcome");
	    d.forward(request, response);

    }
    
    /**
     * @J2EE_METHOD  --  doPost
     * Called by the server (via the service method) to allow a servlet to handle a POST
     * request. The HTTP POST method allows the client to send data of unlimited length
     * to the Web server a single time and is useful when posting information such as credit
     * card numbers. If the HTTP POST request is incorrectly formatted, doPost returns
     * an HTTP 'Bad Request' message.
     * @throws javax.servlet.ServletException
     * @throws java.io.IOException
     */
    public void doPost    (HttpServletRequest request, HttpServletResponse response) 
                throws ServletException, IOException 
    {
		doGet(request,response);
    }
    
    /**
     * @J2EE_METHOD  --  Login
     */
    public Login    ()  
    { 

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -