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

📄 day12.txt

📁 网络购物系统开发详细步骤
💻 TXT
字号:
=========================================================

1, 为 ShoppingSessionFacade 添加 商业方法:

   method name     : modifyShipmentStatus
   return type     : void	
   input parameter : Integer 
   interface       : local



2, 右键点击 ShoppingSessionFacade --> view bean source 

  public void modifyShipmentStatus(
            Integer shipmentid,
            Integer statusId)
            throws ManageException {
    try{

      ShipmentLocal sLocal = shipmentLocalHome.
                       findByPrimaryKey(shipmentid);
      ShipmentstatusLocal shipmentStatusLocal =
                    shipmentStatusLocalHome.
                        findByPrimaryKey(statusId);

      sLocal.setShipmentstatus( shipmentStatusLocal);

      if( !statusId.equals( new Integer(4)) ) {

          OrderLocal orderLocal = sLocal.getOrder();
          OrderStatusLocal osLocal =
                orderStatusLocalHome.
                        findByPrimaryKey(statusId);
          if( statusId.equals( new Integer(3)) ){
            orderLocal.setFinished( 1 );
          }

          orderLocal.setOrderStatus( osLocal );
      }

     
    }catch( FinderException fe ){
      fe.printStackTrace();
      throw new ManageException( fe.getMessage() );
    }
  }

=========================================================

3, 修改 ShoppingSessionFacadeLocal 中的函数声明.

package ejbs;

import javax.ejb.*;
import java.util.*;
import exceptions.OrderException;
import exceptions.ManageException;

public interface ShoppingSessionFacadeLocal 
             extends javax.ejb.EJBLocalObject {

  public void addOrder(double cost, String no, String uid, String payway, Collection lines) throws OrderException;

  public java.util.Collection getAllPayway() 
                              throws OrderException;

  public java.util.Collection getAllShipment() 
                              throws ManageException;

  public Collection getOrderLinesByOrderId(String id) 
                              throws ManageException;

  public void modifyShipmentStatus(Integer shipmentid, Integer statusId) throws ManageException;
}

=========================================================

4,在delegate.ShoppingDelegate中添加方法:

public void modifyShipmentStatus( Integer shipmentid, 
         Integer statusid ) throws ManageException{
    sessionLocal.modifyShipmentStatus(                             shipmentid,statusid);
  }

=========================================================

为modifyShipmentStatus.do 创建Action

  file --> new --> web --> Action

  package :  ec_port_web
  Action  : ModifyShipmentStatusAction

  action path : /modifyShipmentStatus

=========================================================

修改perform方法:

package ec_port_web;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import delegates.ShoppingDelegate;
import exceptions.*;
import java.util.Collection;

public class ModifyShipmentStatusAction extends Action {
  public ActionForward perform(
                 ActionMapping actionMapping, 
                 ActionForm actionForm, 
                 HttpServletRequest request, 
                 HttpServletResponse httpServletResponse) 
{
   
    String[] shipmentIds = request.
                     getParameterValues( "shipment_id" );
    String statusName = request.getParameter( "status" );
    Integer status = null;

    if( statusName.equals( "prepared" ) ){
        status = new Integer(2);
    }
    else if( statusName.equals( "shipped" ) ){
      status = new Integer(3);
    }
    else if( statusName.equals( "received" ) ){
      status = new Integer( 4);
    }

    try{
      ShoppingDelegate sd = new ShoppingDelegate();
      for( int i = 0 ; i< shipmentIds.length ; i++ ){
       
        sd.modifyShipmentStatus(
              new Integer(shipmentIds[i] ),status);
        System.out.println( "modify ok" );
      }

      Collection col = sd.getAllShipment();
      request.getSession().  
               setAttribute( "ALL_SHIPMENT" , col);
      return actionMapping.findForward( "success" );
    }catch( ServiceLocatorException se ){
      se.printStackTrace();
      return actionMapping.findForward( "error" );
    }catch( ManageException me ){
      me.printStackTrace();
      return actionMapping.findForward( "error" );
    }
  }
}

=========================================================

为Action 配置forward

   1) when success
    path : /shipmentMgm.jsp
    name : success

   2) when some exceptions be caught
    path : /fail.jsp
    name : error

=========================================================

⌨️ 快捷键说明

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