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. 打开
<action path="/MyNewControllerCmd" type="com.ibm.commerce.struts.BaseAction" parameter="com.ibm.commerce.sample.commands.MyNewControllerCmd"></action>
3. 刷新Struts配置:
4. 编写Controller接口和实现:
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";
}
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>
默认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