orderlistexec.java

来自「BEA WebLogic Server 8.1大全 = BEA webLogic」· Java 代码 · 共 72 行

JAVA
72
字号
package myApp.Action;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import java.util.Hashtable;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import myApp.Beans.*;

import org.apache.struts.action.Action;

public class OrderListExec extends Action {

  public OrderListExec() {
  }

  public ActionForward
      execute(ActionMapping mapping,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response) throws Exception {

    ActionErrors errors = new ActionErrors();

    /* Example code if the user enters in 1234 for CustomerNo and password
         * the page will be forwarded to orderlistentry else an action error is added
     * displayed back to the front page
     */
    HttpSession session = null;
    try{
      session = request.getSession();
    }catch(Exception e){
      return mapping.findForward("killSession");
    }

    String user = (String) session.getAttribute("user");
    if (user == null) {
      errors.add("loginerror", new ActionError("error.login.expired"));
      super.saveErrors(request, errors);
      return mapping.findForward("login");
    }

    //put the data from the session in the shopping cart;
    dataBean data = new dataBean(
        request.getParameter("item"),
        request.getParameter("qty"),
        request.getParameter("date"));
    Vector order = (Vector) session.getAttribute("order");
    if (order == null) {
      order = new Vector();
    }
    order.add(data);
    session.setAttribute("order", order);
    Enumeration e = request.getParameterNames();
    while(e.hasMoreElements()){
    System.out.println(e.nextElement().toString());
    }
    if (request.getParameter("Enter") != null) {
      return mapping.findForward("success");
    }
    else if (request.getParameter("Display") != null) {
      return mapping.findForward("display");
    }
    else
      return mapping.findForward("logout");
  }

}

⌨️ 快捷键说明

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