项目代码编写技巧(部分)

项目代码编写技巧

关于JavaScript

<!--[if !supportLists]-->1、  <!--[endif]-->使用JAVASCRIPT验证表单,必须同时使用JAVASCRIPT提交表单,而不是使用type=submit的按钮提交表单。这样用户在IE设置中禁止脚本之后,数据验证被屏蔽的同时,表单也无法提交。

<!--[if !supportLists]-->2、  <!--[endif]-->JavaScript变量和函数的命名要求同JAVA代码。局部变量必须使用VAR定义,避免使用全局变量。如:Var i,j;

<!--[if !supportLists]-->3、  <!--[endif]-->在编辑页面的保存、审核、反审核等javascript函数的开始处,一般需要下面代码,以防止页面按钮重复提交问题。

<!--[if gte vml 1]><v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"> <v:stroke joinstyle="miter" /> <v:path gradientshapeok="t" o:connecttype="rect" /> </v:shapetype><v:shape id="_x0000_s1027" type="#_x0000_t202" style='position:absolute; left:0;text-align:left;margin-left:0;margin-top:7.8pt;width:468pt;height:85.8pt; z-index:2' /><![endif]--><!--[if !vml]-->

<!--[endif]--><!--[if !mso]-->
<!--[endif]-->

document.edit.store.disabled = true;

document.edit.Submit.disabled = true;

或者

document.edit.Submit.disabled = false;

document.edit.store.disabled = false;

<!--[if !mso]-->
<!--[endif]--><!--[if !mso & !vml]--> <!--[endif]--><!--[if !vml]-->
<!--[endif]-->  

 

 

 

 

 

 


关于HTML

<!--[if !supportLists]-->1、  <!--[endif]-->要特别注意大小写,虽然在windows下没有区分,但是unix是区分的,并且该问题在windows下可能不能被检出。

<!--[if !supportLists]-->2、  <!--[endif]-->所有链接不允许使用根目录符号“/”,只能以本文件所在目录为开始路径寻找需要的文件,即使用“./”或者“../”两种方式来寻找文件。

<!--[if !supportLists]-->3、  <!--[endif]-->HTML变量的命名按照JAVA代码规范,并且表单变量的名称必须与对应的ValueObject成员变量的名称一致。

<!--[if !supportLists]-->4、  <!--[endif]-->使用缩进的格式,具体格式要求同JAVA代码。(避免使用tab字符,缩进长度为4个空格)

<!--[if !supportLists]-->5、  <!--[endif]-->使用统一的css文件,规范编排格式;所以表格不允许指定高度、字体无需指定sizefont等。

<!--[if !supportLists]-->6、  <!--[endif]-->尽量少用Struts<html>标签库,而是直接写html代码,便于使用可视化编辑工具。

<!--[if !supportLists]-->7、  <!--[endif]-->若非特殊情况,不允许在JSP页面直接写JAVA代码。所以如果使用scriptlet,必须写清楚使用的原因以及影响。

<!--[if !supportLists]-->8、  <!--[endif]-->在HTMLHEAD部分,一般都会有类似的代码,以便于IE确定文件的编码方式和减少IE缓存而导致的数据重复提交、数据不一致等问题,同时指定页面显示风格、引用常用javascript函数包。

<!--[if gte vml 1]><v:shape id="_x0000_s1026" type="#_x0000_t202" style='position:absolute;left:0;text-align:left;margin-left:0;margin-top:7.8pt; width:468pt;height:124.55pt;z-index:1' /><![endif]--><!--[if !vml]-->

<!--[endif]--><!--[if !mso]-->
<!--[endif]-->

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta http-equiv="Expires" content="0">

<meta http-equiv="Pragma" content="no-cache">

<meta http-equiv="Cache-Control" content="no-cache">

<link rel="stylesheet" href="../CSS/style.css" type="text/css">

<script language="Javascript" src="../Script/util.js"></script>

<script language="Javascript" src="../Script/utilfloat.js"></script>

<!--[if !mso]-->
<!--[endif]--><!--[if !mso & !vml]--> <!--[endif]--><!--[if !vml]-->
<!--[endif]-->  

 

 

 


<!--[if !supportLists]-->9、 <!--[endif]-->如果使用DreamWeaver编辑页面,一定要先设置编码为UTF-8

 

关于Struts

<!--[if !supportLists]-->1、  <!--[endif]-->统一使用关键字action的原因是可以方便的实现用户权限判定。

 

页面session超时验证和系统登陆用户验证

系统登陆用户信息统一存放在名称为SYSUser_LoginSession中;每个Action类的perform函数开始部分需要验证session是否超时、用户是否已登陆,单元测试代码如下:

      //begin get the session and the test login user

      HttpSession session = httpServletRequest.getSession();

      SYSSysuser usrTest = SYSSysuserProxy.findSYSSysuser(new Long(1));

      session.setAttribute("SYS_SYSUser_Login",usrTest);

      //end get the session and the test login user

<!--[if !supportLists]-->n         <!--[endif]-->提交集成时上面代码需要修改为:

       //begin get the session and the login user

       HttpSession session = httpServletRequest.getSession(false);

       if (session == null || session.getAttribute("SYS_SYSUser_Login") == null)

         throw new GeneralException(ExceptionType.SESSION_TIME_OUT_EXCEPTION,                                    "In Action.perform()");

       //begin get the session and the login user

 

关于JAVA

<!--[if !supportLists]-->1、  <!--[endif]-->尽量保持简洁明了,长度尽量限制在25个字符以下。

<!--[if !supportLists]-->2、  <!--[endif]-->不要使用下划线、美元符号开头的标识符,尽管这在语法上是允许的。

<!--[if !supportLists]-->3、  <!--[endif]-->使用完整的单词,避免使用只取首字母的简写词和缩写词(除非缩写词比完整词汇的使用更广泛,比如URLHTML)。

<!--[if !supportLists]-->4、  <!--[endif]-->采用客户该领域的词汇(例如:如果用户称他们的客户为Customer而不是Client,就要求使用Customer)。

<!--[if !supportLists]-->5、  <!--[endif]-->避免使用“神秘数”,而是使用常量来代替。

<!--[if !supportLists]-->6、  <!--[endif]-->常量使用大写字母和下划线“_”组成的字符串。

<!--[if !supportLists]-->7、  <!--[endif]-->源代码一行不要超过80个字符,超过80个字符就使用折行(Warpping Line

<!--[if !supportLists]-->8、  <!--[endif]-->避免在源程序中使用Tab

<!--[if !supportLists]-->9、  <!--[endif]-->pakage放在import之前,import必须输入完整的类名。优先列出本项目的包,然后才是标准库。

<!--[if !supportLists]-->10、              <!--[endif]-->空白 Blank

<!--[if !supportLists]-->10.1、     <!--[endif]-->在whileforifswitch等关键字与判断条件之间加上空格。

<!--[if gte vml 1]><v:shape id="_x0000_s1028" type="#_x0000_t202" style='position:absolute;left:0;text-align:left; margin-left:45pt;margin-top:4.15pt;width:369pt;height:54.6pt;z-index:3'> <v:textbox style='mso-next-textbox:#_x0000_s1028' /> </v:shape><![endif]--><!--[if !vml]-->

 
 <!--[endif]--><!--[if !mso]-->
<!--[endif]-->

while (true){

    statements;

}

<!--[if !mso]-->
<!--[endif]--><!--[if !mso & !vml]--> <!--[endif]--><!--[if !vml]-->
<!--[endif]-->  

 

 

 


10.2、在函数的多个参数之间加上空格。

<!--[if gte vml 1]><v:shape id="_x0000_s1029" type="#_x0000_t202" style='position:absolute;left:0;text-align:left; margin-left:45pt;margin-top:4.15pt;width:369pt;height:23.4pt;z-index:4'> <v:textbox style='mso-next-textbox:#_x0000_s1029' /> </v:shape><![endif]--><!--[if !vml]-->

 
 <!--[endif]--><!--[if !mso]-->
<!--[endif]-->

myMethod(arg1, arg2, arg3);

<!--[if !mso]-->
<!--[endif]--><!--[if !mso & !vml]--> <!--[endif]--><!--[if !vml]-->
<!--[endif]-->  

 


10.3、一元运算符与变量之间不能加空格。如:argv++;

 

<!--[if !supportLists]-->11、              <!--[endif]-->变量声明之后,应该马上对变量进行初始化。

<!--[if !supportLists]-->12、              <!--[endif]-->变量应该在块(block)的开始部分集中声明,而不是用到的时候才声明。(临时变    量、循环变量、异常变量除外)

<!--[if !supportLists]-->13、              <!--[endif]-->强烈建议不要用public变量!

<!--[if !supportLists]-->14、              <!--[endif]-->先写注释,后写代码。

<!--[if !supportLists]-->15、              <!--[endif]-->注释信息不仅要包括代码的功能,还应给出原因

<!--[if !supportLists]-->16、              <!--[endif]-->使用Javadoc标记注释,以便于生成api文档。

<!--[if !supportLists]-->17、              <!--[endif]-->保持注释的简洁清晰。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值