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

📄 day10.txt

📁 网络购物系统开发详细步骤
💻 TXT
📖 第 1 页 / 共 2 页
字号:
<title>Untitled Document</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">

<center>
          <form action="orderSubmit.do" method="post">
          <table width="600" border="0" cellspacing="1" 
                 cellpadding="4" bgcolor="3399ff">
           <tr>
             <td colspan="2" align="center"> 
                <font color="#ffffff" class="title">
                收银台</font> 
             </td>
           </tr>
                  <tr>
                     <td bgcolor="#ececec" width="22%" 
                      height="11" align="center">
                        付款方式</td>
                     <td bgcolor="#FFFFFF" height="11">
                         <select name="payway">
<%
                          Iterator i = col.iterator();
                          while( i.hasNext() ){
	                       PaywayDTO payway =                                    (PaywayDTO)i.next();
%>
	                       <option value='<%=payway.getPaywayId()%>' selected>
	                       <%=payway.getPayStyle()%>
	                       </option>
<%
                          }
%>
	                  </select>
                     </td>
		  </tr>
                  <tr>
                     <td bgcolor="#ececec" width="22%" 
                        align="center"height="11">
                        信用卡号</td>
                     <td bgcolor="#FFFFFF" height="11">
                         <input type="text" name="cardNo">
                     </td>
 	          </tr>
                  <tr>
                     <td colspan=2 align="center">
                       <input type="submit" value="确认">
                     </td>
		  </tr>
              </table>
          </form>
</center>
</body>
</html>

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

12,为orderSubmit.do 配置 AcitonForm 

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

   package    : ec_port_web
   ActionForm : OrderSubmitForm
   --> next --> add from jsp --> order.jsp --> add 
   name : payway
   type : java.lang.String 
   --> finish

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

package ec_port_web;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class OrderSubmitForm extends ActionForm {
  private String cardNo;
  private String payway;
  public String getCardNo() {
    return cardNo;
  }
  public void setCardNo(String cardNo) {
    this.cardNo = cardNo;
  }
  public String getPayway() {
    return payway;
  }
  public void setPayway(String payway) {
    this.payway = payway;
  }
  public ActionErrors validate(
             ActionMapping actionMapping,                           HttpServletRequest httpServletRequest) {   
    return null;
  }
  public void reset(ActionMapping actionMapping,
             HttpServletRequest httpServletRequest) {
  }
}

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

13, 修改reset 和 validate 方法

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

14,为orderSubmit.do创建Action

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

    package    : ec_prot_web
    Action     : OrderSubmitAction
    --> next

   Action path    : /orderSubmit
   Formbean name  : orderSubmitForm
   scope          : session
   validate       : true
   input jsp      : order.jsp

  --> finish

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

15, 修改perform 方法

package ec_port_web;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import dto.*;
import javax.naming.*;
import javax.jms.*;
import java.util.*;
import exceptions.OrderException;
import ejbs.ShoppingCartLocal;
import util.User;


public class OrderSubmitAction extends Action {
  public ActionForward perform(
         ActionMapping actionMapping, 
         ActionForm actionForm, 
         HttpServletRequest request, 
         HttpServletResponse httpServletResponse) {
    
    OrderSubmitForm form = (OrderSubmitForm) actionForm;
    ShoppingCartLocal cart = 
        (ShoppingCartLocal)request.getSession().
              getAttribute( ShoppingCartLocal.CART_ATTR);
    OrderDTO order = new OrderDTO(
         cart.getAll(),
         new PaywayDTO(new nteger(form.getPayway()),null),
         form.getCardNo(),
         ((User)request.getSession().
               getAttribute( User.USER_ATTR )).getId(),
         cart.getCost());
    try{
      this.sendMessage( order );
      return actionMapping.findForward( "success" );
    }catch( OrderException oe ){
      oe.printStackTrace();
      return actionMapping.findForward( "error" );
    }
  }

  public void sendMessage( OrderDTO order)   
                         throws OrderException{
    QueueConnection conn = null;
    QueueSession session = null;
    QueueSender sender = null;
    Queue q = null;

    try{
      Context ctx = new InitialContext( );
      QueueConnectionFactory factory = 
       ( QueueConnectionFactory )
            ctx.lookup("jms/QueueConnectionFactory" );
      conn = factory.createQueueConnection();
      session = conn.createQueueSession(
             false,QueueSession.AUTO_ACKNOWLEDGE);
      q = (Queue) ctx.lookup( "jms/FileQueue" );
      sender = session.createSender(q);
      ObjectMessage oMsg = 
           session.createObjectMessage(order);
      sender.send( oMsg );
    }catch( NamingException ne ){
      ne.printStackTrace();
    }
     catch( JMSException je ){
       je.printStackTrace();
       throw new OrderException( je.getMessage() );
    }
    finally{
      if( sender != null ) try{ 
            sender.close();} catch( Exception e ){}
      if( session != null ) try{ 
            session.close();} catch( Exception e ){}
      if( conn != null ) try{ 
           conn.close();} catch( Exception e ){}
    }

  }
}
==========================================================

16,为OrderSubmitAction 配置 forward

   a) when success

    path : /index.jsp
    name : success

   b) when some exceptions be caught

    path : /fail.jsp
    name : error

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

17, 双击ejb-module 创建MDB

   点击右键 --> create ejb --> Message-dirven bean

  bean name               : MessageBean
  transaction type        : bean
  ackownlage mode         : Atuo-ackownlage
  message selector        : 
  destination type        : javax.jms.Queue
  destination name        : jms/FileQueue
  connection factory name : jms/QueueConnectionFactory

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

18,右键点击 MessageEJB --> add --> field 
   name: sessionLocal
   type: ShoppingSessionFacadeLocal

-=========================================================

19,双击MessageEJB的图标 --> ejb local reference , 添加 对ShoppingSessionFacadeEJB的引用:

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

20,右键点击MessageEJB --> view bean source

    在 ejbCreate 方法中初始化sessionLocal

 public void ejbCreate() throws CreateException {
    
    try{
      ServiceLocator locator = 
              ServiceLocator.getInstance();
      ShoppingSessionFacadeLocalHome home = 
                (ShoppingSessionFacadeLocalHome)
                     locator.getEJBLocalHome(                        "java:comp/env/ejb/ShoppingEJB" );
      sessionLocal = home.create();
    
    }catch( ServiceLocatorException se ){
      se.printStackTrace();
      throw new CreateException( se.getMessage() );
    }
  }

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

21, 修改onMessage方法

public void onMessage(Message msg) {
    ObjectMessage oMsg = (ObjectMessage)msg;

    try{
      OrderDTO order = (OrderDTO)oMsg.getObject();
      Collection col = order.getItems();
    
      sessionLocal.addOrder(order.getCost(),
                            order.getCardNo(),
                            order.getUserid(),
                            order.getPayway().
                              getPaywayId().intValue()+"",
                            order.getItems());

    }catch( JMSException je ){
      je.printStackTrace();
    }
     catch( OrderException oe ){
       oe.printStackTrace();
    }
  }

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

⌨️ 快捷键说明

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