WCS学习笔记(第二天) - 增加一个控制器命令

1. 在接口和实践关联表CMDREG注册登记MyNewControllerCmd命令:

    a. 启动wcs服务器;

    b.  IE打开:URL: http://localhost/webapp/wcs/admin/servlet/db.jsp

  c.  注册MyNewControllerCmd命令:

insert into CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION, CLASSNAME, TARGET) values (10051,'com.ibm.commerce.sample.commands.MyNewControllerCmd', 'This is a new controller command for the business logic tutorial.',  'com.ibm.commerce.sample.commands.MyNewControllerCmdImpl','Local');

 

2. 在struts-config-ext.xml添加JSP页面配置:
  a. 打开 Stores >WebContent >WEB-INF > struts-config-ext.xml , 在<action-mappings> 标签中添加action标签配置

<action path="/MyNewControllerCmd" type="com.ibm.commerce.struts.BaseAction" parameter="com.ibm.commerce.sample.commands.MyNewControllerCmd"></action>

 

3. 刷新Struts配置:
  a. 打开 admin console,在Site/Store中登陆Site

  b. 点击Configuration >Registry, 选择Struts Configuration选项并 Update ->Refresh

 

4. 编写Controller接口和实现:
  a.WebSphereCommerceServerExtensionsLogic >src > com.ibm.commerce.sample.commands新建接口类MyNewControllerCmd.java

package com.ibm.commerce.sample.commands;

import com.ibm.commerce.command.ControllerCommand;

public interface MyNewControllerCmd extends ControllerCommand {
	/**
	*	defaultCommandClassName is the default implementation
	*	class used by command factory to instantiate this
	*	command if this interface is not defined in the CMDREG table.
	*/
	public static final String COPYRIGHT = com.ibm.commerce.copyright.IBMCopyright.SHORT_COPYRIGHT;

// set default command implement class
	static final String defaultCommandClassName = "com.ibm.commerce.sample.commands.MyNewControllerCmdImpl";
	
}


  b.WebSphereCommerceServerExtensionsLogic >src > com.ibm.commerce.sample.commands新建接口类MyNewControllerCmd.java

package com.ibm.commerce.sample.commands;

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

public class MyNewControllerCmdImpl extends ControllerCommandImpl implements MyNewControllerCmd {

	private static final String COPYRIGHT = com.ibm.commerce.copyright.IBMCopyright.SHORT_COPYRIGHT;

/**
 * This constructor calls the superclass constructor.
 */
public MyNewControllerCmdImpl() {
	super();
}


/**
 * The business logic for this controller command. For this default implementation
 * we simply call validateParameters. Command writers who overwrite this method
 * call super() as the first line in their method if they want to call validateParameters.
 *
 * @exception com.ibm.commerce.exception.ECException An ECException is thrown in the case of an error .
 */
public void performExecute() throws ECException {

    /// perform server side parameter checking

	super.performExecute();

    /// Create a new TypedProperties for output purposes.

 	TypedProperty rspProp = new TypedProperty();

    /// see how the controller command calls the JSP

	rspProp.put(ECConstants.EC_VIEWTASKNAME, "MyNewView");
	setResponseProperties(rspProp);

}

/**
 *
 * ControllerCommandImpl calls validateParameter in performExecute.
 * It is the responsibility of the command writers to implements
 * this method if they want to perform server side parameter checking.
 * They should either calls validateParameters inside their performExecute
 * or calls super.performExecute() as the first statement in the
 * performExecute method.
 *
 *
 * @exception CommandException.
 */

public void validateParameters() throws ECException {

}
}



 

5. 创建xml注册文件:

  a. 在WCDE_installdir\xml\policies\xml(如C:\IBM\WCDE_PRO70\xml\policies\xml)新建MyNewControllerCmdACPolicy.xml文件:

<?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.sample.commands.MyNewControllerCmdResourceCategory"
			ResourceBeanClass="com.ibm.commerce.sample.commands.MyNewControllerCmd">
		<ResourceAction Name="ExecuteCommand"/>
	</ResourceCategory>
	
<ResourceGroup Name="AllSiteUserCmdResourceGroup"  OwnerID="RootOrganization">
		 <ResourceGroupResource Name="com.ibm.commerce.sample.commands.MyNewControllerCmdResourceCategory" />
	</ResourceGroup>

</Policies>


 

 

6. 注册页面:

  a. 停止server

  b. 命令定位到WCDE_installdir\bin (如:cd C:\IBM\WCDE_PRO70\bin),执行下面命令

默认derby数据库:    acpload MyNewControllerCmdACPolicy.xm
其它数据库(DB2、Oracle):acpload db2user db2userpassword MyNewControllerCmdACPolicy.xml DB2USER



7. 测试:

  a. 启动server

  b. 访问:  http://localhost/webapp/wcs/stores/servlet/MyNewControllerCmd (注:由于缓存可在url后加如: ?StoreId=10051 )

 

参考: http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.developer.tutorial.doc/tutorial/ttd13.htm 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值