deploy.path=/data/jsp/xxxxxxxx.com
<?xml version="1.0"?>
<project name="xxxx" basedir="." default="usage">
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="web.dir" value="WebRoot"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="webapps"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="usage">
<echo message=""/>
<echo message="${name} build file"/>
<echo message="-----------------------------------"/>
<echo message=""/>
<echo message="Available targets are:"/>
<echo message=""/>
<echo message="build --> Build the application"/>
<echo message="deploy --> Deploy application as directory"/>
<echo message="deploywar --> Deploy application as a WAR file"/>
<echo message=""/>
</target>
<target name="build" description="Compile main source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false"
failonerror="true" includeantruntime="false" encoding="GBK">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
<copy todir="${build.dir}" preservelastmodified="true">
<fileset dir="${src.dir}">
<!--<include name="**/*.*"/>-->
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="deploy" depends="build" description="Deploy application">
<mkdir dir="${deploy.path}/${name}"/>
<copy todir="${deploy.path}/${name}" preservelastmodified="true">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
<target name="deploywar" depends="build" description="Deploy application as a WAR file">
<war destfile="${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<target name="clean" description="Clean output directories">
<delete>
<fileset dir="${build.dir}">
<include name="**/*.*"/>
</fileset>
</delete>
</target>
<target name="undeploy" description="Un-Deploy application">
<delete>
<fileset dir="${deploy.path}/${name}">
<include name="**/*.*"/>
</fileset>
</delete>
</target>
</project>
主要功能:
1、自动将表单封装成对象(类似Struts2)
2、自动根据对象产生增删改查sql语句(类似hibernate)
3、支持Spring动态注入,可以把自定义的Action 交给Spring去进行管理
4、自定义的tab标签库
5、支持伪静态功能
伪静态实现,可以用正则表达式!~
这个框架,差不多就是一个SSH最精简的实现。
配置非常灵活简单,比起三大框架来说,容易多了,而且包就一个而已,非常的小!
包和类:
org.pan.code 这是核心类的包
主要的类:
过滤器-转发控制器-Action管理器-字段类型转换器-Spring支持类-JDBC支持类-SQL创建类
主要的配置文件是:request.xml
百度网盘下载地址:http://pan.baidu.com/share/link?shareid=467157&uk=470382596
Q:599194993
有兴趣的联系我,一起完善!~
附上部分源代码:
最核心的代码,Action管理器:
package org.pan.code;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.pan.convetor.FieldConvertor;
import org.pan.exception.InitializeActionException;
import org.pan.support.ServletActionContent;
import org.pan.util.MethodsUitl;
import org.pan.util.StringUitl;
/**
* 请求request请求数据 调用对应的类去进行处理
* @author Pan
*
*/
public class ActionManage {
private HttpServletRequest request; //请求对象
private HttpServletResponse response; //响应对象
private Map<String, Object> map=new HashMap<String, Object>(); //map对象
private String result; //返回类型
private String classPath; //类的路径
private String methodName; //需要操作的方法
private Object bean; //对象的实例 可以是从Spring中获取到的
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public String getMethodName() {
return methodName;
}
public String getResult() {
return result;
}
private Map<String, Object> getMap() {
return map;
}
public ActionManage(Object bean,HttpServletRequest request,HttpServletResponse response,String classPath,String methodName){
this.request=request;
this.response=response;
this.classPath=classPath;
this.methodName=methodName;
this.bean=bean;
invokeMap(); //将请求的值放入map
try {
init(); //初始化
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 将请求的值放入map
*/
private void invokeMap(){
Iterator it=request.getParameterMap().entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry=(Map.Entry)it.next();
String key=entry.getKey().toString();
String value=StringUitl.getStringArray((String[])entry.getValue());
map.put(key, value);
}
}
/**
* 将相关对象设置到用户的Action中
* @throws InitializeActionException
* @throws NoSuchMethodException
* @throws SecurityException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
private void init() throws Exception{
//获取类对象
Class class1=null;
Object object=null;
try{
//
if(this.bean!=null){
object=bean;
class1=bean.getClass();
}else{
class1=Class.forName(classPath);
//初始化对象
object=class1.newInstance();
System.out.println("初始化对象");
}
}catch (Exception e) {
System.err.println(e);
throw new InitializeActionException();
}
//给对象设置字段参数
initField(class1,object);
//调用方法
this.result=invokeMethod(class1, object);
}
/**
* 初始化字段
*/
private void initField(Class class1,Object object) throws Exception{
//获取字段集合
Field[] fields=class1.getDeclaredFields();
//获取方法集合
Method [] methods=class1.getDeclaredMethods();
for (Field field : fields) {
String name=(String)map.get(field.getName());
//给指定赋值
String MethodName="set"+StringUitl.capitalize(field.getName());
if(MethodsUitl.exist(methods,MethodName)){
field.setAccessible(true);
//field.set(object, map.get(field.getName()));
Object value=map.get(field.getName());
if(value!=null){
FieldConvertor.convertor(object, field, value.toString());
}
}
}
}
/**
* 调用方法
*/
private String invokeMethod(Class class1,Object object) throws Exception{
//创建ServletActionContent实例对象
ServletActionContent servlet=new ServletActionContent();
servlet.setRequest(request);
servlet.setResponse(response);
servlet.setSession(request.getSession());
//创建参数类型
Class parameter[]=new Class[]{ServletActionContent.class};
Method method=class1.getMethod("setServletActionContent", parameter);
//参数值
Object obj[]=new Object[]{servlet};
method.invoke(object, obj); //操作方法
//调用execute 方法
//Method execute=class1.getMethod("execute", new Class[0]);
Method execute=class1.getMethod(this.methodName, new Class[0]);
Object type=execute.invoke(object, new Class[0]);
return type.toString(); //设置返回类型
}
}
请求管理器:
package org.pan.controller;
import java.util.List;
import javax.servlet.FilterChain;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.pan.bean.Request;
import org.pan.bean.Result;
import org.pan.bean.SpringBean;
import org.pan.code.ActionManage;
import org.pan.code.Configuration;
import org.pan.spring.SpringBeanFactory;
import org.pan.support.ActionSupport;
import org.pan.util.ResultUitl;
/**
* 请求控制器
* @author Pan
*
*/
public class RequestController {
private HttpServletRequest request;
private HttpServletResponse response;
private FilterChain chain;
public RequestController(ServletRequest request,ServletResponse response,FilterChain chain){
this.request=(HttpServletRequest)request;
this.response=(HttpServletResponse)response;
this.chain=chain;
}
/**
* 处理请求
*/
public void doFilter() throws Exception{
String filepath=request.getServletPath().substring(1); //当前这个文件的名称
//通过配置文件得到跳转对象和一些操作的方法
Configuration configuration=new Configuration(request);
System.out.println("filepath:"+filepath);
//伪静态
Request rt=configuration.findByLike(filepath);
if(rt==null){
System.out.println(rt);
System.out.println("error:"+configuration.find(filepath));
rt=configuration.find(filepath);
}
//如果rt还是null 就直接跳过不处理
if(rt==null){
chain.doFilter(request, response);
return ;
}
//如果没有配置类路径,就当作转发器使用直接转发到结果页
if(rt.getClassPath()==null||rt.getClassPath()==""){
Result rs=ResultUitl.findResult(rt.getResults(), ActionSupport.SUCCESS);
if(rs==null){
chain.doFilter(request, response);
}else{
request.getRequestDispatcher(rs.getPath()).forward(request, response);
}
return;
}
//Spring support
SpringBeanFactory factory=new SpringBeanFactory(request);
Object object=null;
if(rt.getId()!=null||rt.getId()!=""){
//xml配置中需要开启支持
if(SpringBean.getSupport()){
object=factory.getBean(rt.getId());
}
}
//用户Action管理器
ActionManage actionManage=new ActionManage(object,request,response,rt.getClassPath(),rt.getMethod());
String result=actionManage.getResult();
//寻找放返回值对应的页面
List<Result> results= rt.getResults();
String path="";
for (Result result2 : results) {
if(result2.getName().equals(result)){
//得到对应的路径
path=result2.getPath();
}
}
//转发到对应的页面
if(!path.equals("")){
request.getRequestDispatcher(path).forward(request, response);
}
//上面没有进行处理那就是配置不争取或者面页不存在
else{
chain.doFilter(request, response);
}
}
}
配置管理器和xml读取:
package org.pan.code;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.pan.bean.Request;
import org.pan.bean.Result;
import org.pan.exception.ReadRequestXmlException;
/**
* 配置管理器
* @author Pan
*
*/
public class Configuration {
private List<Request> requests;
public Configuration(HttpServletRequest request){
XmlRead xmlRead=new XmlRead(request);
try {
requests=xmlRead.read();
} catch (ReadRequestXmlException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 寻找配置文件中的request节点对象
* @param name
* @return
*/
public Request find(String name){
for (Request request : requests) {
System.out.println("name:"+name+" - "+request.getPag
概念(来自度娘)
系统优化原来是系统科学(系统论)的术语,现在常用作计算机方面的术语。它尽可能减少计算机执行的进程,更改工作模式,删除不必要的中断让机器运行更有效,优化文件位置使数据读写更快,空出更多的系统资源供用户支配,以及减少不必要的系统加载项及自动启动项。当然优化到一定程度可能略微影响系统稳定性,但基本对硬件无害。
系统优化的一般步骤分为五步,不同的公司可能会省略其中的部分文档,但是大体的思路是一致的。
1、发现问题
一般性能的问题无非是系统工作效率低下,最常见的就是对数据库的CRUD操作缓慢、导出数据无响应等。有了问题我们应该精准的定位问题,尽可能的将问题的描述量化。在这里可以借助相应的工具进行一些性能测试,得到了详细的测试报告就可以为下一步的分析优化做好铺垫。
工欲善其事必先利其器,下面介绍几个比较有用的工具,篇幅有限具体的用法读者可以自己去度娘。
Httpwatch:IE插件,用来查看在浏览器中操作的详细情况。下图为Httpwatch某个查询的耗时记录:
JavaVisualVM:Java自带资源分析工具。下图为Java VisualVm记录某段循环的截图
LoadRunner:强大的压力测试工具,通过以模拟上千万用户实施并发负载及实时性能监测的方式来确认和查找问题。
根据得到性能测试结果要写一份性能测试报告为下一步工作提供依据,写性能测试报告一般有以下几点需要注意:
a) 测试使用数据是否为现场数据
b) 测试使用的客户端是什么配置
c) 服务器数据库端的配置
d) 选择的测试条件
e) 每个功能测试次数,平均耗时为多少
f) 每次查询返回的数据量
g) 数据库里对应表里的数据总量
h) 将测试记录写成文档,对于不达标的记录高亮显示
2、分析问题
根据上面得到的测试报告找到系统性能瓶颈的位置,然后从外向里添加日志,打印出各方法的执行时间,这样便很快就能找到问题的具体位置。将分析结果写入文档,为下一步提供依据。
切记:优化一定要对系统进行深入分析,找到性能问题根源切入点,而不被表象迷糊,对症下药。例如我们发现内存高了,首先想到不应该是扩大内存,而是为什么如此消耗内存,用工具(Java VisualVM)看看内存消耗在什么地方,想办法解决。
3、提出方案
根据分析结果提出合理的解决方案,然后写成文档提交审批。这里特别要注意的是解决方案的合理性,换句话说就是一定要考虑优化的成本。
从成本上面考虑大致的顺序如下。
数据库 ----> 应用层 ----> Web层 ----> 硬件
当然具体问题还需要具体分析(在后面的文章中将详细介绍更层次的优化方法)。一般来说在数据库上建立索引、分区等操作要比在应用层重构算法来的省时省力;应用层和Web层基本上是一致的,但和硬件比起来在软件层次的优化还是第一位的。就像上面说的,内存不够用了不应该去考虑换机器、加内存,而是找到内存开销大的地方,解决之。
4