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

📄 additem.java

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

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class AddItem extends HttpServlet
{
    
    /**
     * @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 
    {
    	 ShoppingSession shoppingSession = (ShoppingSession) request.getSession().getAttribute("shoppingSession");
    	if ( shoppingSession == null ) {
	      error(response);
	    }
	    String id = request.getParameter("inventoryid");
	    Integer integer = new Integer(id);
	    sessionBean.addItem(integer);
	    RequestDispatcher d = request.getRequestDispatcher("shoppingcart");
	    d.forward(request, response);
	    return;

    }
    
    /**
     * @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);
    }
    
    private void error(HttpServletResponse response) throws IOException
    {
	    response.setContentType(CONTENT_TYPE);
	    PrintWriter out = response.getWriter();
	    out.println("<html>");
	    out.println("<head><title>Error</title></head>");
	    out.println("<body>");
	    out.println("<p>The information was requested in error</p>");
	    out.println("</body></html>");
	  }
    
    /**
     * @J2EE_METHOD  --  AddItem
     */
    public AddItem    ()  
    { 

    }
}

⌨️ 快捷键说明

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