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

📄 day02.txt

📁 网络购物系统开发详细步骤
💻 TXT
字号:
为struts配置资源文件

a) 在工程中,新建package ec_port_web ,用于存放struts相关的
   类。
b) 在ec_port_web中新建资源文件 
   new --> file 
   填写:    name : ApplicationResource  ,
            type : properties ,

c) 编辑ApplicationResource.properties :
   login.title=Login Page
   login.name=Name
   login.password=Password:
   login.submit=Login

   errors.name.required=Must input user ID
   errors.password.required=Must input password
   errors.header=Error List<ul><hr/>
   errors.footer=</ul>
   (* 如果要输入中文字,需要通过unicode转换工具 )

d) 在struts-config.xml 中注册资源文件
   鼠标双击struts-config.xml.
   在屏幕作下角出现Message Resources, 选中该项,在窗口
   右侧出现图形界面,--> add
   填写 : parameter: ec_port_web.ApplicationResource 
           (* 前面要加包的名称,后面不加扩展名 )
           key : ( 不加配置 )

e) 存盘,这时 察看web-config.xml的源文件的改变
   在图形界面下方选择source,载源文件中会有这样一个元素:
   <message-resources 
        parameter="ec_port_web.ApplicationResource" />

==========================================================
编写注册页面 
a)  name : register.jsp --> next 
    tagliberary : struts1.1 --> bean , html

b)  form:
    ( *
      action: 请求路径
      method: 请求方法
      name  : 对应的formBean的名字
      type  : formBean的实现类,加包名
    *)
    <html:form action="userRegister.do" method="post"
                              name="userRegisterForm"                        type="ec_port_web.UserRegisterForm">
    <p align=center>
        <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%"                                  align="center" height="11">用户名</td>
            <td bgcolor="#FFFFFF" height="11"> 
                  <html:text property="name"/>
            </td>
          </tr>
             <tr>
            <td bgcolor="#ececec" width="22%"                      align="center" height="11">密码</td>
            <td bgcolor="#FFFFFF" height="11">                   <html:password property="password"/>
            </td>
          </tr>
             <tr>
            <td bgcolor="#ececec" width="22%"                 align="center" height="11">确认密码</td>
            <td bgcolor="#FFFFFF" height="11">
                  <html:password property="pwdConfirm"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                           align="center">地址一</td>
            <td bgcolor="#FFFFFF">
                <html:text property="street1"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                               align="center">地址二</td>
            <td bgcolor="#FFFFFF">
                <html:text property="street2"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                                  align="center">城市</td>
            <td bgcolor="#FFFFFF">
                 <html:text property="city"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                             align="center">省份</td>
            <td bgcolor="#FFFFFF">
                <html:text property="province"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                               align="center">国家</td>
            <td bgcolor="#FFFFFF">
                <html:text property="country"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                              align="center">邮政编码</td>
            <td bgcolor="#FFFFFF">
                <html:text property="zip"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                           align="center"> E-mail</td>
            <td bgcolor="#FFFFFF"> 
                <html:text property="email"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                           align="center"> 住宅电话</td>
            <td bgcolor="#FFFFFF"> 
               <html:text property="homephone"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                                 align="center"> 手机</td>
            <td bgcolor="#FFFFFF">
                <html:text property="cellphone"/>
            </td>
          </tr>
          <tr>
            <td bgcolor="#ececec" width="22%"                             align="center">办公室电话</td>
            <td bgcolor="#FFFFFF">
                <html:text property="officephone"/>
            </td>
          </tr>
        </table>
        <p align=center>
            <html:submit>Register</html:submit>
        </p>

</td>
  </tr>
</table>
</html:form>
       
==========================================================

为register.jsp 创建formBean

a) file --> new --> web --> actionForm
   填写
   package    : web_port_web
   actionForm : ec_port_web.UserRegisterForm

   --> next --> add from jsp  --> register.jsp --> next
   formBean name : userRegisterForm

   (注意:
     actionForm : 对应<html:form>中的type
     formbean name : 对应<html:form>中的name
b) 重写validate 和 reset 方法

c) 编译

d) 察看struts-config.xml原文件,其中因该多出一个元素:
   
   <form-beans>
	<form-bean name="userRegisterForm"                    type="ec_port_web.UserRegisterForm" />
   </form-beans>

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

创建UserRegisterAction 

a) file --> new --> web --> Action
   填写 package : ec_port_web
        Action  : UserRegisterAction
       --> next 
   ActionPath    : /userRegister
   form bean name: userRegisterForm
   scope         : session
   validate      : true
   input jsp     : register.jsp

   其中: 
   ActionPath : Action的侦听路径,与页面form中的Action相
                对应,将.do去掉即可
   form bean name : Action 需要用到的form bean
   scope          :form bean 放在什么区域
   input jsp      : 请求是由那个页面发送的

   --> finish

b) 为 UserRegisterAction  配置forward:
    
   双击struts-config.xml ,进入图形界面
   在走下角展开Action Mapping 选中/userRegister
   在窗口右下方选中forward标签 --> add

   1) path : registerSuccess.jsp
      name : success

   1) path : fail.jsp
      name : fail

c) 存盘 , 察看struts-config.xml 源代码,因该添加了如下元素:
    <action-mappings>
        <action name="userRegisterForm"                 type="ec_port_web.UserRegisterAction"                 validate="true" 
                input="/userRegister.jsp" 
                scope="session" path="/userRegister">
            <forward name="registerSuccess"                      path="/index.jsp" />
            <forward name="registerFail"                                        path="/fail.html" />
      
        </action>
    </action-mappings>

d) 实现Action中的perform 方法:
   

package ec_port_web;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import exception.*;
import dto.*;
import javax.ejb.CreateException;
import delegate.*;

public class UserRegisterAction extends Action {
  public ActionForward perform(ActionMapping                    actionMapping, ActionForm actionForm,                    HttpServletRequest httpServletRequest,
                 HttpServletResponse httpServletResponse) {
    
    UserRegisterForm userRegisterForm = 
                  (UserRegisterForm)actionForm;
    try{
      UserMgmDelegate ud = new UserMgmDelegate();
      UserDTO user = new UserDTO(                                               userRegisterForm.getName(),
                       userRegisterForm.getPassword());
     ContactInfoDTO info = new ContactInfoDTO(
                      userRegisterForm.getName(),
                      userRegisterForm.getStreet1(),
                      userRegisterForm.getStreet2(),
                      userRegisterForm.getCity(),
                      userRegisterForm.getProvince(),
                      userRegisterForm.getCountry(),
                      userRegisterForm.getZip(),
                      userRegisterForm.getEmail(),
                      userRegisterForm.getHomephone(),
                      userRegisterForm.getCellphone(),
                      userRegisterForm.getOfficephone());

       ud.userRegistry(user,info);
      return actionMapping.findForward( 
                               "registerSuccess" );
    }catch( ServiceLocatorException se ){
      se.printStackTrace();
      return actionMapping.findForward( "fail" );
    }
     catch( CreateException ce ){
       ce.printStackTrace();
       return actionMapping.findForward( "fail" );
     }
     catch( RegistryException le ){
       le.printStackTrace();
       return actionMapping.findForward( "registerFail" );
     }
  }
}

e) 编译
==========================================================


创建ear
 操作:file--->new----->Enterprise---->EAR,点[OK]。
name:ec_port_ear
EJB Modules : 选中ec_port_em
WebApp Nodes : 选中ec_port
其他项默认。


==========================================================
部署,测试

⌨️ 快捷键说明

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