Thinking in Jawf

You should have your own thought!

星期四, 六月 25, 2009

Project Note(1.7)

今天,项目管理变更:项目组织架构从采用maven管理的SCM(Software Configuration Management)变为Ant(或说倒退到了Ant)。原因, 为SIT做准备,maven 部署到weblogic是没什么问题,但项目大了,control使得不是那么理想,经常会有些莫名的问题,所以用ant部署到weblogic使得更简单透明!?


Note Date:2008-12-01

标签:

星期二, 三月 10, 2009

Project Note(1.6)

Before the performance or coding in the module of your project, IDENTITY of indicating whether you can do the process,or influene the other process, such as whether is completed or terminated and what you should change others. All of this IDENTITY should be marked and make coder or designer clearly.

Note Date:2008-11-22

标签:

Project Note(1.5)

Java的引用(reference)本质上与C指针没什么区别,使用引用时,实例的值发生变化,其他引用所指向的依然是这个发生了变化的实例。所以使用时需特别谨慎。

Note Date:2008-11-11

标签:

Project Note(1.4)

When Project is going to carry out SIT, Team Leader will try to control the quality of his/her code before SIT. It is IIT. Team Leader will asked his/her developers to test the code each other. But it didn't take effect nutil the Team Leader make a plan, and espercially required the man/woman whom to be tested site beside the tester.

Note Date:2008-11-3

标签:

星期一, 三月 09, 2009

Project Note(1.3)

1. When meeting with process application, we should control the process's transection when it canceled, system will roll back.
2. In a progress of application, there should be several status stand for application status as "Draft", "Submited", "Processing", "Accepted", "Rejected".

Note Date:2008-10-20

标签:

Project Note(1.2)

When project is going to completed, so there is no longer needing so many developer. So the PM will go to release the developer...

Note Date: 2008-10-13

标签:

星期二, 十二月 23, 2008

Project Note(1.1)

Interface for interacting:
S1-Sub-Module--
                            --- 
S2-Sub-Module          ---
                                         - --M1 Module -
   
S3-Sub-Module      ---                                    -
                                                         |
Common API    ---                                          -
         |                                                 |                 
     When S3 call for S2's function.                 -
                                                            |                    -Project
                                                                       -
                                                    M2 Module -    -
 
                                                     |              -

                                            Common API  -
                                                          |
                            When M1 call for M2's function.

Note Date:2008-8-5

标签:

Project Note(0.3)

做外包的确是件仔细的活。在画UI时,其实很需要仔细留意需求所给的UI文档,它已经做得很仔细了,细节都考虑到了,所以,你所在的环节也不能大意。不然给后面的周期带来的问题所造成的费用会随时间而成正比提升。

Note Date:2008-3-19

标签:

Project Note(0.2)

项目中需要使用的common类或代码是要提前考虑好,而且尽可能多的情况。例如javascript来取时间到输入框,那有的情况就会有:(1)DD/MM/YYYY;(2)DD/MM;(3)MM/YYYY;(4)YYYY;(5)YYYY-MM-DD;...等,所以你要考虑好接口以满足不同的情况的输入。

Note Date:2008-3-18

标签:

Project Note(0.1)

Project Manager或Team Leader或相关人员需要在项目开始前或任务分配前,制定和预测尽可能多的(一切)standard, 不然那将会导致项目进行后很多的头痛的问题。

Note Date:2007-3-17

标签:

星期四, 四月 26, 2007

从简单实例了解Spring的控制反转IoC(Inversion of Control)

Spring 的核心是IoC,而IoC模式也只是一种思想,很早以前就有了“依赖倒转原则”和“面向抽象编程”,就像Hibernate的ORM思想一样,重要的是学习人家怎么把思想应用到开发上,或框架上上。这样的设计,又一次地把解耦合的思想灌述进来,实在是很精彩的思想。 这里还是让大家从实例来了解和分享IoC把。
以对象导向的方式来设计,依赖反转(Dependency Inversion)的解释为“程序不应该依赖实现,而是依赖于抽象接口”。看以下程序:





public class Business{
private FloppyWrite writer= new
FloppyWriter();
...
public void save()
{
...
writer.saveToFloppy();
}

}



Business类的设计中,存盘的需求依赖于实际的FloppyWrite对象,若想要将存储介质改为USB磁盘,则必须修改Business的程序,无法重用Business类。
通过接口这样申明一个接口:





public interface IDeviceWriter{
public void saveToDevice()
{
}

}



那么Business类可以这样设计了,遇到存盘时,将其依赖于IDeviceWriter接口,而不是依赖于实际的FloppyWriter这个实现:





public class Business{
private
IDeviceWriter;

public void setDeviceWriter(IDeviceWriter writer)
{
this.writer=
writer;
}

public void save(){
...
writer.saveToDevice();
}

}




这样的设计Business类就可以重用了,倘若要存储至Floppy或USB磁盘,这只需要针对这两种需求分别实现接口即可:
针对Floppy存储设计一个FloppyWriter类:




public class FloppyWriter implement IDeviceWriter{
public void saveToDevice()
{
...
//实际存储至Floppy的代码

}

}



或针对USB磁盘存储设计一个UsbDiskWriter类:




public class UsbDiskWriter implement IDeviceWriter{
public void saveToDevice()
{
...
//实际存储至Floppy的代码

}

}



这样的话,采用USB磁盘存储只需编写一个配置程序如下:
Business business= new Business();
business.setDeviceWriter(new UsbDiskWriter());
business.save();
而Spring融入这个思想的同时,还将选择实现的配置写入XML,这样更改配置更加方便。


现在再来理解下Dependency Inversion的解释:“程序不应该依赖实现,而是程序和实现都要依赖于抽象接口”。
在Martin Fowler的文章中也谈过Dependency Injection(依赖注入),其分三种实现方式:Interface injection,Setter injection(setter方法注入),Constructor injection(构造时注入)。而这里用到的是 Setter方式,也是Spring鼓励的方式。


是不是已经理解了,是不是感觉心里的特别的舒畅,我也是这样的,很高兴跟大家分享我领悟的!

现在来看这张图片,进行J2EE开发中的DAO设计时应用上这种依赖关系,不用多说了,图片已经把这种关系解释得很微妙了。

标签:

星期三, 一月 03, 2007

Web2.0的腾飞

        今天看了会《程序员》,看到了软件中国2006风云榜,顺便也到csdn上去看了下,杂志上只有十佳,网站上更多点。带着去看的心境当然是新意的软件或技术,当然现在网站也是软件。
        最让人敏感和心旷神怡的还是Web2.0带来的新奇。基于软件向导模式的豆瓣网 (
www.douban.com),使用Python技术与Web2.0完美结合,能将本质是论坛的东西做成这样是很不错了。当打开爱迪网(www.aiddi.com)后,其耳目一新的Web网页竟然成了软件UI,这正是他的主题:i桌面--在线桌面,个人门户。虽然其美化成分过多,但还是没有盖过它的前台技术。Rss与Ajax技术的结合得如此成熟,看到他的创始人竟然在XML领域积累了5年的经验,那的确是该将技术通过这样表达出来阿。还有我要地图网(www.51ditu.com),让我在国内终于看到了能与googlemap比的地图网。还有很多精彩的网站我就不一一去说了。
        看到这些,只能说Web2.0在腾飞,web2.0让网站的开发越来越向软件开发靠近了,新颖的东西甚至让人称口叫绝。当然,在学别人技术的同时,我们程序员也得耳听八方,眼观四海,新颖的东西就在我们创造的一瞬间,那就是创新了,像feedsky(
www.feedsky.com),抓虾(www.zhuaxia.com),clocklink(www.clocklink.com这是国外的)都是在web发展中,随blog的普及,为web贡献出来的,当然贡献也是给自己创造财富,所以想自己创业的Programmer们要有自己的感觉并看准时机,对软件界发展的熟悉可能会给你提供这个感觉。风云榜上的10佳最具创新技术的奇虎360安全卫士的创始人兼CEO周鸿袆,应该就是这样的人。看到和听到流氓软件的横行与反流氓软件的呼唤,而自己又是熟悉流氓软件的创作者,果断地离开雅虎,成立奇虎,果然成功了,360安全卫士的名声还打得这么响。更有趣的是猎户星在线写诗机(www.dopoem.com),以前只有听说过还没真正注册了去尝试下,今天顺便就注册并“写”了首诗,写出来还蛮搞笑的,很明显他是拥有庞大的数据库和复杂的算法,然后来拼接用户输入的关键词。室友Byron看到了,也注册了个,一口气“写”了5首。Web和应用程序开发的结合又一次展现在用户面前。而猎户星在线写诗机的创始人却抓住了这个机遇。
        看了一些,也思考了一些,好像这些也都是做一个成功的人的哲理。恩,学习又开始有动力和目标了。 

对登陆filter的小研究

         最近在给贫困生管理网站添加登录时尝试了使用过滤器,一直寻找质料时针对的url过滤都是<url-pattern>/LoginServlet</url-pattern>(举例)或<url-pattern>/*</url-pattern>,也就是说都是针对单个对Servlet和所有的url 进行过滤,因为使用<url-pattern>/*</url-pattern>过滤比较省事,尝试和调试了很久,发现行不通,因为当你登录的<首页>得到请求时,/*会针对所有的url过滤,包括图片、css、js等通通要过滤下,所以在使用/*的时候要将过滤器写得庞大下,要将url分解,让某些url直接通过,若为了偷懒,也可以如以下这样做:

      <filter>
        
<filter-name>LoginChecker</filter-name>
        
<filter-class>filter.LoginChecker</filter-class>
        
<init-param>
            
<param-name>targetURI</param-name>
            
<param-value>/index.jsp</param-value>
        
</init-param>
    
</filter>    
    
<filter-mapping>
        
<filter-name>LoginChecker</filter-name>
        
<url-pattern>/LoginServlet</url-pattern>
    
</filter-mapping>
    
<filter-mapping>
        
<filter-name>LoginChecker</filter-name>
        
<url-pattern>/H00101servlet</url-pattern>
    
</filter-mapping>
    
<filter-mapping>
        
<filter-name>LoginChecker</filter-name>
        
<url-pattern>/common/control.jsp</url-pattern>
    
</filter-mapping>


        对特定的url,如Servlet,jsp文件,进行过滤,这样做又带来了一些麻烦,就是要把所有的Servlet通通给添进来。不过在配置Servlet的时候也可以这样配置:



<servlet-mapping>  
    
<servlet-name>LoginCheckr</servlet-name>  
    
<url-pattern>/servlet/LoginCheckr</url-pattern>  
</servlet-mapping>  
<servlet-mapping>  
    
<servlet-name>H00101servlet</servlet-name>  
    
<url-pattern>/servlet/H00101servlet</url-pattern>  
</servlet-mapping>


然后配置filter-mapping:

<filter-mapping>
    
<filter-name>LoginChecker</filter-name>
    
<url-pattern>/servlet/*</url-pattern>
</filter-mapping>


这样倒是省了不少事。



/**附加我用到的LoginChecker.java
package filter;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
 * 对到达web.xml中配置了的某些请求进行过滤,登录过的可以通过,
 *登录中的可以到达指定位置,未登陆的转向登陆页面
 * 
@author Jawf
 * @Team Passion.Homsoft
 
*/

public class LoginChecker implements Filter {
    
private ServletContext context;
    
private String targetURI;

    
public void init(FilterConfig config) throws ServletException {
        context 
= config.getServletContext();
        targetURI 
= config.getInitParameter("targetURI");
    }


    
public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) 
throws IOException, ServletException {
        HttpServletRequest httpRequest 
= (HttpServletRequest) request;
        HttpServletResponse httpResponse 
= (HttpServletResponse) response;
        HttpSession session 
= httpRequest.getSession(false);
        
if (session != null{
            String login 
= (String) session.getAttribute("Login");
            
if (login.equals("OK")) {
                System.out.println(
"logined");
                chain.doFilter(httpRequest, httpResponse);
                
return;
            }
 else if (login.equals("logining")) {
                System.out.println(
"1:"+new String(httpRequest.getRequestURI()));
                
if (new String(httpRequest.getRequestURI())
                        .equals(
"/ZDBWeb/LoginServlet")) {
                    System.out.println(
"logining...");                    
                    chain.doFilter(httpRequest, httpResponse);
                    
return;
                }

            }
 else {
            }

            session.removeAttribute(
"Login");
        }
 else {
            System.out.println(
"not logined");
            System.out.println(
"2:"+new String(httpRequest.getRequestURI()));
            
if (!(new String(httpRequest.getRequestURI())
                    .equals(targetURI))) 
{
                request.setAttribute(
"msg""请先登录!");
            }
            
        }


        
// httpRequest.getRequestDispatcher(targetURI).forward(httpRequest,httpResponse);
        StringBuffer requestURL = httpRequest.getRequestURL();
        String query 
= httpRequest.getQueryString();
        System.out.println(
"3:"+query);
        
if (query != null)
            requestURL.append(query);
        httpRequest.setAttribute(
"originalURL"new String(requestURL));
        System.out.println(
"4:"+targetURI);
        httpRequest.getRequestDispatcher(targetURI).forward(httpRequest,
                httpResponse);

    }


    
public void destroy() {

    }

}


附:


一、Servlet过滤器的概念:
***************************************************************************************
Servlet过滤器是在Java Servlet规范2.3中定义的,它能够对Servlet容器的请求和响应对象进行检查和修改。   


Servlet过滤器本身并不产生请求和响应对象,它只能提供过滤作用。Servlet过期能够在Servlet被调用之前检查Request对象,修改Request Header和Request内容;在Servlet被调用之后检查Response对象,修改Response Header和Response内容。


Servlet过期负责过滤的Web组件可以是Servlet、JSP或者HTML文件。 
***************************************************************************************



二、Servlet过滤器的特点:
***************************************************************************************
A.Servlet过滤器可以检查和修改ServletRequest和ServletResponse对象
B.Servlet过滤器可以被指定和特定的URL关联,只有当客户请求访问该URL时,才会触发过滤器
C.Servlet过滤器可以被串联在一起,形成管道效应,协同修改请求和响应对象
***************************************************************************************



三、Servlet过滤器的作用:
***************************************************************************************
A.查询请求并作出相应的行动。
B.阻塞请求-响应对,使其不能进一步传递。
C.修改请求的头部和数据。用户可以提供自定义的请求。
D.修改响应的头部和数据。用户可以通过提供定制的响应版本实现。
E.与外部资源进行交互。
***************************************************************************************



四、Servlet过滤器的适用场合:
***************************************************************************************
A.认证过滤
B.登录和审核过滤
C.图像转换过滤
D.数据压缩过滤
E.加密过滤
F.令牌过滤
G.资源访问触发事件过滤
H.XSL/T过滤
I.Mime-type过滤
***************************************************************************************



五、Servlet过滤器接口的构成:
***************************************************************************************
所有的Servlet过滤器类都必须实现javax.servlet.Filter接口。这个接口含有3个过滤器类必须实现的方法:


A.init(FilterConfig):
这是Servlet过滤器的初始化方法,Servlet容器创建Servlet过滤器实例后将调用这个方法。在这个方法中可以读取web.xml文件中Servlet过滤器的初始化参数


B.doFilter(ServletRequest,ServletResponse,FilterChain):
这个方法完成实际的过滤操作,当客户请求访问于过滤器关联的URL时,Servlet容器将先调用过滤器的doFilter方法。FilterChain参数用于访问后续过滤器


B.destroy():
Servlet容器在销毁过滤器实例前调用该方法,这个方法中可以释放Servlet过滤器占用的资源
***************************************************************************************



六、Servlet过滤器的创建步骤:
***************************************************************************************
A.实现javax.servlet.Filter接口
B.实现init方法,读取过滤器的初始化函数
C.实现doFilter方法,完成对请求或过滤的响应
D.调用FilterChain接口对象的doFilter方法,向后续的过滤器传递请求或响应
E.销毁过滤器
***************************************************************************************



七、Servlet过滤器对请求的过滤:
***************************************************************************************
A.Servlet容器创建一个过滤器实例
B.过滤器实例调用init方法,读取过滤器的初始化参数
C.过滤器实例调用doFilter方法,根据初始化参数的值判断该请求是否合法
D.如果该请求不合法则阻塞该请求
E.如果该请求合法则调用chain.doFilter方法将该请求向后续传递
***************************************************************************************



八、Servlet过滤器对响应的过滤:
***************************************************************************************
A.过滤器截获客户端的请求
B.重新封装ServletResponse,在封装后的ServletResponse中提供用户自定义的输出流
C.将请求向后续传递
D.Web组件产生响应
E.从封装后的ServletResponse中获取用户自定义的输出流
F.将响应内容通过用户自定义的输出流写入到缓冲流中
G.在缓冲流中修改响应的内容后清空缓冲流,输出响应内容
***************************************************************************************


九、Servlet过滤器的发布:
***************************************************************************************
A.发布Servlet过滤器时,必须在web.xml文件中加入<filter>元素和<filter-mapping>元素。


B.<filter>元素用来定义一个过滤器:
属性                   含义
filter-name    指定过滤器的名字
filter-class    指定过滤器的类名
init-param    为过滤器实例提供初始化参数,可以有多个


C.<filter-mapping>元素用于将过滤器和URL关联:
属性                     含义
filter-name    指定过滤器的名字
url-pattern    指定和过滤器关联的URL,为”/*”表示所有URL
***************************************************************************************



十一、Servlet过滤器使用的注意事项
***************************************************************************************
A.由于Filter、FilterConfig、FilterChain都是位于javax.servlet包下,并非HTTP包所特有的,所以其中所用到的请求、响应对象ServletRequest、ServletResponse在使用前都必须先转换成HttpServletRequest、HttpServletResponse再进行下一步操作。


B.在web.xml中配置Servlet和Servlet过滤器,应该先声明过滤器元素,再声明Servlet元素



C.如果要在Servlet中观察过滤器生成的日志,应该确保在server.xml的localhost对应的<host>元素中配置如下<logger>元素:
<Logger className = “org.apache.catalina.logger.FileLogger”
directory = “logs”prefix = “localhost_log.”suffix=”.txt”
timestamp = “true”/>

CSS原来还可以这样用

         最近给学院网站添了个分栏,表面上很简单,却还含了不少技术成分。当然这东西是通过js+css实现的。首先是js的编写,不过算是简单的,重头戏是css的编写。
先附上js:        这里是是显示信息的两栏,class为activecontent表示层可见,hidedencontent反之,写在css中。



<script type="text/javascript">
    tabCount 
= 2;
    
function changeTab(tabIndex)
    
{
        
for (i = 1; i <= tabCount; i++)
        
{
            tab 
= document.getElementById("FenceTab" + i);   
            content 
= document.getElementById("TopTenContent" + i);
            marquee 
= document.getElementById("marquee" + i);
            marquee.start();
            
if (i == tabIndex)
            
{
                tab.className 
= "active";   
                content.className 
= "activecontent";                
            }

            
else
            
{
                tab.className 
= "";
                content.className 
= "hiddencontent";
                marquee.stop();
            }

        }

    }

</script>


 



<%--begin 分栏  Author: Jawf--%>
 
<div id="TopTenContent1" class="activecontent">
   
<marquee direction="up" scrollamount="1" scrolldelay="15" id=marquee1  onmouseover=marquee1.stop() onmouseout=marquee1.start()>      
    
<%//里面是从数据库中取公告的代码%>
   
</marquee>
 
</div>    
 
<div id="TopTenContent2" class="hiddencontent"> 
   
<marquee direction="up" scrollamount="1" scrolldelay="15" id=marquee2  onmouseover=marquee2.stop() onmouseout=marquee2.start()>     
    
<%//里面是从数据库中取通知的代码%>
   
</marquee>
 
</div>



        这里是选择哪一栏的标记,我采用的是图片,在css中可以看得出来是切换图片 



 <div id="fence">
   
<li id="fence1"><id="FenceTab1" onmouseover="changeTab(1);" onclick="return false;" class="active" href="#"><img src="common/images/spacer.gif" alt="学院公告" width="81" height="20" /></a> </li>
   
<li id="fence2"><id="FenceTab2" onmouseover="changeTab(2);" onclick="return false;" href="#"><img src="common/images/spacer.gif" alt="教学通知" width="81" height="20" /></a></li>
 
</div>
 
<%--end 分栏--%> 


附css:



/*begin 分栏 Author: Jawf*/
ul 
{
 margin
: 0;
 padding
: 0;
}

#rightbottom #fence
{
 height
: 20px;
 width
: auto;
 line-height
: 20px;
 background-position
: left;
 text-align
: left;
}

#rightbottom li 
{
  display
: inline;
  overflow
: hidden;
  list-style-type
: none;
  margin
: 0px; }


#rightbottom #fence1
{
 margin
:2px 0px 0px 0px;
 padding
:0px;
 border
:0px;
 width
:81px;
 height
:20px;
 text-align
:left; 
}

#rightbottom #fence1 a
{background: url(../images/fence11.gif) no-repeat left bottom;}
#rightbottom #fence1 a.active 
{background: url(../images/fence12.gif) no-repeat left bottom;}
#rightbottom #fence1 a.active:hover
{background: url(../images/fence12.gif) no-repeat left bottom;}
#rightbottom #fence2
{
 margin
:2px 0px 0px 0px;
 padding
:0px;
 border
:0px;
 width
:81px;
 height
:20px;
 text-align
:left; 
}

#rightbottom #fence2 a
{background: url(../images/fence21.gif) no-repeat left bottom;}
#rightbottom #fence2 a.active
{background: url(../images/fence22.gif) no-repeat left bottom;}
#rightbottom #fence2 a.active:hover
{background: url(../images/fence22.gif) no-repeat left bottom;}

.activecontent
{
 text-align
: justify;
 padding
: 2px;
 z-index
: 2;
 border-top-width
: 1px;
 border-right-width
: 1px;
 border-bottom-width
: 1px;
 border-left-width
: 1px;
 border-top-style
: none;
 border-right-style
: none;
 border-bottom-style
: none;
 border-left-style
: none;
}


.activecontent a 
{
  text-decoration
: none;
  color
: #00f; }


.activecontent a:hover
{
    text-decoration
: underline;
}


.activecontent ol
{
    margin
: 5px 5px 5px 25px !important;
    margin
: 5px 5px 5px 30px;
    padding
: 0px;
}


.activecontent li
{
    margin
: 0px;
    padding
: 0px;
}


.hiddencontent
{
    display
: none;
}

/*end 分栏*/

初涉Struts

         最近来给学院网站做了点东西,学院网站是采用J2EE Struts框架搭建的,整体感觉就是Struts框架很不错,应用到企业级开发应该很适合。Struts使得整个开发模块很清晰,各层关系也很清晰,当然最主要是体现在控制层,页面转发通过struts-config.xml体现得很清晰。
         ActionServlet 是框架的核心,应该是Command 部分。ActionServlet(Command)创建并使用Action、ActionForm和ActionForward,而struts-config.xml文件配置该 Command。对于新的业务逻辑可以直接通过创建Action和ActionForm来解决。应用程序的整个逻辑流程都存储在一个分层的文本文件中,使程序员更容易查看和理解。
        ActionForm 维护 Web 应用程序的会话状态。 ActionForm 是一个抽象类,通过继承它来使用。可能有一个由HTML 表单设置的 UserActionForm,Struts 将使用 HttpServletRequest 中相应的域设置 UserActionForm 的状态没有太多讨厌的 request.getParameter() 调用。
        Action 类是业务逻辑的一个包装。 Action 类的用途是将 HttpServletRequest 转换为业务逻辑。要使用Action ,请创建它的子类并覆盖 process() 方法。
        Error 类包括 ActionError 和 ActionErrors 。ActionError 封装了单个错误消息。 ActionErrors 是ActionError 类的容器,View 可以使用标记访问这些类。 ActionError 是 Struts 保持错误列表的方式。 

星期日, 十月 22, 2006

Thinking in JSP

        以前觉得做网站不怎么样,不过接触jsp后,我改变了我的想法,现在我还是决定把我们的方向Java方向搞好,因为java有个JVM虚拟机,所以开发的程序,可以跨平台使用,jsp本身倒是没什么,但是因为与Java结合起来了,兴起了很多技术,主要是J2EE的开发,从MVC分层架构,到struts,sping,甚至Hibernate,都是把网站要做的事情封装到了Java类中,可读性和移植性以及管理方面都很好,所以觉得java还是蛮好的东西,程序运行可以做到Write Once,Run Anywhere!开发可以做到Learn Once,Write Anywhere!
        Faighting!