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

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

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

public class FloppyWriter implement IDeviceWriter...{
public void saveToDevice()...{
...
//实际存储至Floppy的代码
}
}
public class UsbDiskWriter implement IDeviceWriter...{
public void saveToDevice()...{
...
//实际存储至Floppy的代码
}
}
<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-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”/>
最近给学院网站添了个分栏,表面上很简单,却还含了不少技术成分。当然这东西是通过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"><a 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"><a 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 分栏*/ 最近来给学院网站做了点东西,学院网站是采用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 保持错误列表的方式。
以前觉得做网站不怎么样,不过接触jsp后,我改变了我的想法,现在我还是决定把我们的方向Java方向搞好,因为java有个JVM虚拟机,所以开发的程序,可以跨平台使用,jsp本身倒是没什么,但是因为与Java结合起来了,兴起了很多技术,主要是J2EE的开发,从MVC分层架构,到struts,sping,甚至Hibernate,都是把网站要做的事情封装到了Java类中,可读性和移植性以及管理方面都很好,所以觉得java还是蛮好的东西,程序运行可以做到Write Once,Run Anywhere!开发可以做到Learn Once,Write Anywhere!
Faighting!