Websphere Commerce Suite 架构开发一个模块的流程

看了一周的wcs框架,做了一个小的注册页面模块,熟悉了一下开发框架和流程,开发步骤如下:

 

1. 在Struts-config-ext.xml文件中,建立转向静态页面register.jsp的配置如下:

    <forward className="com.ibm.commerce.struts.ECActionForward" name="IndexRegister"   path="/ConsumerDirect/register.jsp"/> 

    <action path="/IndexRegister" type="com.ibm.commerce.struts.BaseAction"/>

这里因为没有Command处理,所以没有parameter属性的配置。

register.jsp页面代码如下:

 <%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>注册页面</title>
</head>
<body bgcolor="pink">
    <center>
        <h3 style="font-size:20pt">注册信息</h3>
        <form name="reg" method="post" action="register_gentlemen">
            <table width="300" border="1" cellspacing="0" cellpadding="2">
                <tr>
                    <td align="right" width="30%" height="25">姓名:</td>
                    <td align="left" width="70%" height="25" >&nbsp;&nbsp;<input type="text" id="user_id" name="username" size="23" maxlength="15" style="left-margin:5"></td>
                </tr>
                <tr>
                    <td align="right" width="30%" height="25">密码:</td>
                    <td align="left" width="70%" height="25" >&nbsp;&nbsp;<input type="password" id="password_id" name="password_name" size="25" maxlength="15" style="left-margin:5px"></td>
                </tr>
                <tr>
                    <td align="right" width="30%" height="25">重复密码:</td>
                    <td align="left" width="70%" height="25" >&nbsp;&nbsp;<input type="password" id="repassword_id" name="repassword_name" size="25" maxlength="15" style="left-margin:5px"></td>
                </tr>
            </table>
            <table width="300" border="0">
                <tr>
                    <td colspan="2" height="5">
                    </td>
                </tr>
                <tr>
                    <td colspan="2" height="25" width="100%" align="right" valign="bottom">
                        <input type="submit" name="sub_name" value="确 认">&nbsp;&nbsp;&nbsp;<input type="reset" name="reset_name" value="取 消">
                    </td>
                </tr>
            </table>
        </form>
    </center>
</body>
</html>

 

2.  对写好的register.jsp页面进行access controll注册。注册代码放在F:/WCToolkitEE60/xml/policies/xml/IndexRegisterPolicies.xml中,配置如下:

    <?xml version="1.0" encoding="utf-8" standalone="no" ?>
      <!DOCTYPE Policies SYSTEM "../dtd/accesscontrolpolicies.dtd">
      <Policies>
          <Action Name="IndexRegister" CommandName="IndexRegister"></Action>
          <ActionGroup Name="AllSiteUsersViews"  OwnerID="RootOrganization">
              <ActionGroupAction Name="IndexRegister"/>
          </ActionGroup>
     </Policies>

 

3. cmd进入控制台,运行acpload  IndexRegisterPolicies.xml  (注意一定要停止服务)。

 

4. 注册信息要提交到Command进行处理,首先定义一个Command接口。如下:

    package com.ibm.commerce.test.commands;

    import com.ibm.commerce.command.ControllerCommand;


    public interface RegisterCmd extends ControllerCommand {
        static final String defaultCommandClassName="com.ibm.commerce.test.commands.RegisterCmdImpl";
    }

 

5. 定义Command实现类,如下:

package com.ibm.commerce.test.commands;

import com.ibm.commerce.command.ControllerCommandImpl;
import com.ibm.commerce.datatype.TypedProperty;
import com.ibm.commerce.exception.ECException;
import com.ibm.commerce.server.ECConstants;


public class RegisterCmdImpl extends ControllerCommandImpl implements
  RegisterCmd
{

 public void performExecute()throws ECException{
  super.performExecute();
  
  TypedProperty tp = this.getRequestProperties();
  
  String username = tp.getString("username");
  String password = tp.getString("password_name");
  String repassword = tp.getString("repassword_name");
  
  TypedProperty response = new TypedProperty();
  response.put("username", username);
  response.put("password", password);
  response.put("repassword", repassword);
  
  response.put(ECConstants.EC_VIEWTASKNAME, "welcome_gentlemen");
  this.setResponseProperties(response);
 }
}

 

6. 在数据库中注册Command,运行如下:

    insert into CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION, CLASSNAME, TARGET) values (CD_storeent_ID,'com.ibm.commerce.test.commands.RegisterCmd ', '', 'com.ibm.commerce.test.commands.RegisterCmdImpl','Local');

 

7. 配置Command的访问权限:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
     <!DOCTYPE Policies SYSTEM "../dtd/accesscontrolpolicies.dtd">
     <Policies>
        <Action Name="ExecuteCommand" CommandName="Execute"></Action>
       
        <ResourceCategory Name="com.ibm.commerce.test.commands.RegisterCmdResourceCategory" ResourceBeanClass="com.ibm.commerce.test.commands.RegisterCmd">
            <ResourceAction Name="ExecuteCommand"/>
        </ResourceCategory>
       
        <ResourceGroup Name="AllSiteUserCmdResourceGroup"  OwnerID="RootOrganization">
            <ResourceGroupResource Name="com.ibm.commerce.test.commands.RegisterCmdResourceCategory" />
        </ResourceGroup>
    </Policies>

 

8.在struts-config.ext.xml中配置Command的action,这里没有forward的配置,定向在Command的方法中设置,如下:

    <action path="/register_gentlemen" type="com.ibm.commerce.struts.BaseAction" parameter="com.ibm.commerce.test.commands.RegisterCmd"></action>

 

9.配置最后的welcome页面:

<action path="/welcome_gentlemen" type="com.ibm.commerce.struts.BaseAction"></action>

<forward name="welcome_gentlemen" path="/ConsumerDirect/welcome.jsp" className="com.ibm.commerce.struts.ECActionForward"></forward>

页面的代码如下:

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>欢迎页面</title>
</head>
<body bgcolor="pink">
    <center>
        <h3>welcome!</h3>
        username:&nbsp;<c:out value="${username}"/><br>
        password:&nbsp;<c:out value="${password}"/><br>
        repassword:&nbsp;<c:out value="${repassword}"/>
    </center>
</body>
</html>

 

10. 最后对页面的access controll进行注册

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
      <!DOCTYPE Policies SYSTEM "../dtd/accesscontrolpolicies.dtd">
      <Policies>
          <Action Name="welcome_gentlemen" CommandName="welcome_gentlemen"></Action>
          <ActionGroup Name="AllSiteUsersViews"  OwnerID="RootOrganization">
              <ActionGroupAction Name="welcome_gentlemen"/>
          </ActionGroup>
</Policies>

 

 

最后运行即可:http://localhost/webapp/wcs/stores/servlet/IndexRegister

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值