最近发布
[Extjs4.0] keel_jdbc2.0后台管理模块 (包含前后台源码)
地址如下:
http://czpae86.iteye.com/blog/1058754
项目源码见附件!!
安装方法:
1,导入jar包.用到的jar包如下,请自己在网上下载,都是比较常见的.
2,还原数据库(在附件"keel数据库备份.rar"上)数据库使用的是MS SERVER 2005,
如果更改数据库请添加相应的jar包,和修改db.properties文件.
3,部署到tomcat(本人使用的是tomcat5.0)
4,启动tomcat,浏览器输入,如http://localhost:8080/keel_jdbc1.0/ (端口自己按实际情况更改)
5,帐号,密码都为(admin)
版本 V1.0
1:前台界面暂时只有登录,后续版本会增加复杂的页面!(用Extjs已经3年)
2:后台主要如下
一,通过一个servlet作为前后台交互入口,代码如下:
package keel.util; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.HashMap; import java.util.InvalidPropertiesFormatException; import java.util.Map; import java.util.Properties; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; /** * 前后台交互入口 * @author 蔡治平 * @since 2011-04-23 */ public class KeelServlet extends HttpServlet { private Logger logger = Logger.getLogger(KeelServlet.class); private final String doGetMethod = "doGet"; private final String doPostMethod = "doPost"; private final String classConfigPath = "classConfig.xml"; /** * 通过get方法提交将会调用该方法 */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); dataOut(request, response, doGetMethod); } /** * 通过post方法提交将会调用该方法 */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); //response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); dataOut(request, response, doPostMethod); } /** * 打包提交的参数 * @param request * @param method * @return Map */ private MapdataInToMap(HttpServletRequest request,String method){ Enumeration names = request.getParameterNames(); Map map = new HashMap (); while(names.hasMoreElements()){ String name = names.nextElement().toString(); String value = request.getParameter(name); if(method.equals(doGetMethod)){ try { byte [] bytes = value.getBytes("ISO-8859-1"); map.put(name, new String(bytes,"UTF-8")); } catch (UnsupportedEncodingException e) { logger.error("打包提交参数出现异常,原因:"+e); } }else{ map.put(name, value); } } return map; } /** * 获得类名 * @param name * @return String */ private String getClassName(String name){ Properties prop = new Properties(); String clsName = ""; try { prop.loadFromXML(Thread.currentThread().getContextClassLoader().getResourceAsStream(classConfigPath));//this.getClass().getClassLoader().getResourceAsStream(classConfigPath) clsName = prop.getProperty(name); if(clsName==null){ logger.error(classConfigPath+"配置中没有定义key="+name); }else if(clsName.trim().equals("")){ logger.error(classConfigPath+"配置中key="+name+"的值为空"); }else{ logger.info("从"+classConfigPath+"中成功获取类配置key="+name+"-->"+clsName); } } catch (InvalidPropertiesFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return clsName; } /** * 该方法打包前台提交参数,通过映射调用方法,然后返回结果到前台 * @param request * @param response * @param method */ @SuppressWarnings("unchecked") private void dataOut(HttpServletRequest request, HttpServletResponse response, String method){ Map dataIn = this.dataInToMap(request,method); dataIn.put("session", request.getSession()); String clsName = getClassName(request.getParameter("clsName")); String methodName = request.getParameter("methodName"); Map dataOut = CallMethod.callMethod(clsName, methodName, dataIn); String k = (String) dataOut.get("dataOut"); PrintWriter out; try { out = response.getWriter(); out.print(k); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
二,前台传入类别名(classConfig.xml中配置),方法名,通过反射执行类方法
package keel.util; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Map; /** * 通过反射执行类方法 * @author 蔡治平 * @since 2011-04-23 */ public class CallMethod { public static Map callMethod(String clsName,String method, MapdataIn) { Class cls = null; try { cls = Class.forName(clsName); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Class partypes[] = new Class[1]; partypes[0] = Map.class; Method meth = null; try { meth = cls.getMethod(method, partypes); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } Object returnValue = null; try { returnValue = meth.invoke(cls.newInstance(), dataIn); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } Map dataOut = (Map) returnValue; return dataOut; } }
三,一个数据库连接池和一些数据库操作的封装,代码请看附件项目.
希望有你想要的东西! 请多给意见!
注意:该项目没有用到hibernate,spring,struts,dwr等框架!!