📄 updateitem.java
字号:
package com.j2eeapp.cdstore.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.j2eeapp.cdstore.bean.ShoppingSession;
public class UpdateItem 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");
try
{
String itemId = request.getParameter("itemId");
String quantity = request.getParameter("quantity");
shoppingSession.updateItem(itemId,quantity);
}
catch (Exception ex) {
ex.printStackTrace();
}
RequestDispatcher d = request.getRequestDispatcher("ordercompleted");
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 -- UpdateItem
*/
public UpdateItem ()
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -