酷文首页  
站内搜索:
网站地图 | RSS订阅 | 收藏本站
经济论文
证券金融
工商管理
会计审计
法学论文
医药论文
社会论文
教育论文
计算机论文
艺术论文
哲学论文
财政税收
财务管理
公共管理
理学论文
政治论文
文学论文
工学论文
文化论文
实用文档
应用文
自考成考
演讲稿
法律文书
子栏目导行↓
网站赞助商↓
本类热点↓
本类更新↓
热门标签↓
网摘收藏↓

基于JAVA的长沙市公交系统乘车指南的设计与实现

作者:郭 程
来源:酷文网
点击:
载入中...
加入时间:2008-08-02
字体大小:[  ]

作为中文的软件开发必然要显示中文,而在JSP页面中要显示中文必须声明JSP页面的中文编码规则,在本项目中统一使用的是UTF-8。(当然也可以用GB2312,或GBK) ,如下所示:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
在Struts的JSP页面中的form对应着一个ActionForm Bean,还必须指定其action属性,因为form中指定的数据首先都要经过ActionForm的验证,然后传递特定的Action中去处理。在表单form中action属性是必须的,action属性是form表单提交数据时通过Struts配置文件找到指定Action和ActionForm类的来处理相应的数据。通过action="/registerAction.do"把JSP里的信息传到action去处理,当填写完用户注册的信息后,点击提交后去到对应的action里找对应的方法进行处理数据。
由于公交查询管理系统的几个功能的视图层设计的总体框架与用户注册功能相似,所以这里就不再赘述。
ActiomForm简介
ActionForm是用来封装HTTP请求中的数据。并将用户提交的数据自动填充(在相应的action的execute方法被调用之前)到form的属性中,这样就无需手工调用不用request.getParameter(…).但开发人员必须继承这个ActionForm类,如下代码一样:
 public class LoginForm extends ActionForm {
 ......
         }
ActionForm开发步骤:首先,继承ActionForm类。然后,将每个属性对应提交表单中的一个输入域。接着,为每个属性提供getter和setter方法。再提供validate(...) and reset()方法,但是这一步是可靠的。最后,在struts_config.xml中配置如下:
   <form-beans>
     <form-bean name="aForm" type="form.AForm" />
  <form-bean name="bForm" type="form.BForm" />
   </form-beans>
公交查询管理系统中的功能涉及到的ActionForm Bean有多个,我都分别采用了静态验证表单,如下是用户注册的ActionForm的关键代码:

public class registForm extends ActionForm{
 //所有属性都为私有的
 private static final long serialVersionUID = 1L;
 private String userName=null;
 private String userPassword=null;
 private String userPassword2=null;
 private String phoneNo=null;
 private String email=null;
 public registForm(){
  
 }
 //以下都为部分属性的SET及GET方法
 
 public void setUserPassword(String userPassword){
  this.userPassword=userPassword;
 }
 
 
 public void setUserPassword2(String userPassword2){
  this.userPassword2=userPassword2;
 }
 
 public String getUserPassword2(){
  return userPassword2;
 }
 
 public void setEmail(String email){
  this.email=email;
 }
 
 public String getEmail(){
  return email;
 }
 //带全部属性的构造方法
 public void reset(ActionMapping mapping,
   HttpServletRequest request) {
  this.userName=null;
  this.userPassword=null;
  this.userPassword2=null;
  this.phoneNo=null;
  this.email=null;
 }
 //如果一个Form想继承ActionForm必顺实现validate方法
 public ActionErrors validate(ActionMapping mapping,
   HttpServletRequest request) {
   ActionErrors errors = new ActionErrors();
/判断用户名,密码,二次输入的密码,邮箱只要有一个为空就跳转到错误页面,
//给出错误信息
   if (userName==null || userPassword==null || userPassword2==null
     || phoneNo==null || email==null){
    errors.add(ActionErrors.GLOBAL_MESSAGE,
     new ActionMessage(""));                      
   }  
   
(3)ActionForm Bean的属性均为私有属性,其对应的有一对get()和set()方法;
(4)validate()方法在此userForm中没有任何验证,因为对应此JSP的表单中所有的数据都是让用户选择输入的,一般不会有灾难性的错误;
(5)视图层的界面
图 7是系统主登录的界面,图 8是站点管理主页面系统的界面风格是统一的。


图 7  登录界面
Fig 7  Login Interface

图 8  站点信息管理主界面
Fig 8  Station Information Admin Interface
4.3.2  控制层的实现
控制层主要介绍一下Action类,它是控制用户请求和业务逻辑的桥梁。所有控制层类要继承这个Action类,供ActionServlet所驱动。Action类的职责:调用业务逻辑方法将控制权返回给ActionServlet并且提供相关的路由信息。具体的Action类都是按以下步骤来开发的:首先,继承Action类。接着,覆盖 execute(...)方法。然后,返回ActionForward对象(提供决策信息给ActionServlet选择适当的视图响应用户)。最后,在struts-config.xml中配置。配置时都是按照如代码来配置的,
 <action-mappings>
     <action input="/index.jsp"   :ActionForm验证失败的跳转页面
      name="aForm"                 :与Action对应的FormBean对象
      path="/myAction"             :请求URI(/myAction.do) 转贴于 酷文网-论文下载中心 http://www.coolwen.net


共13页: 上一页 [1] [2] [3] [4] [5] [6] 7 [8] [9] [10] [11] [12] [13] 下一页

网摘收藏:
免责声明 | 关于我们 | 广告联系 | 友情链接 | 网站地图 | 共同合作
免费论文 毕业论文 毕业论文范文 酷文网(www.coolwen.net) 版权所有 coolwen.net 2007,All Rights Reserved
E-mail:hui_love#tom.com(为防止垃圾邮件请把#换成@) 点击这里给我发消息 点击这里给我发消息
湘ICP备07003917号