logo资料库

JEECMS2源码的解读.doc

第1页 / 共25页
第2页 / 共25页
第3页 / 共25页
第4页 / 共25页
第5页 / 共25页
第6页 / 共25页
第7页 / 共25页
第8页 / 共25页
资料共25页,剩余部分请下载后查看
安装
jcaptcha 自定义验证码
Xml
Spring事务
Struts2与Spring之间URL跳转
后台登陆
jcaptcha 自定义验证码例子
Hibernate Interceptor
Spring jdbc
进入前台
标签解读
freemarker+struts2应用
JeeCMS2 源码阅读 安装 .................................................................................................................................................... 1 jcaptcha 自定义验证码 .....................................................................................................................7 Xml..................................................................................................................................................... 7 Spring 事务 .........................................................................................................................................8 Struts2 与 Spring 之间 URL 跳转 ................................................................................................... 11 后台登陆 .......................................................................................................................................... 12 jcaptcha 自定义验证码例子 ...........................................................................................................15 Hibernate Interceptor........................................................................................................................16 Spring jdbc........................................................................................................................................16 进入前台 .......................................................................................................................................... 18 标签解读 .......................................................................................................................................... 21 freemarker+struts2 应用 ...................................................................................................................23 安装 您还没有安装JEECMS,3秒钟之后自动跳转到安装页面。
如果您的浏览器长时间没有反应,请直接点击JEECMS 安装。 install/index.html:一般是同意安装页
进入安装数据库和参数页: 域名:
value="<%=request.getServerName()%>"/> 系统已经检测出您的域名,请勿改动 部署路径: 系统已经检测出您的部署路径,请勿改动 安装: <%@page contentType="text/html; charset=gbk" language="java" import="com.jeecms.core.util.*,java.util.*"%> <% String dbFileName = "/install/db/jeecms-db-2.4.2-final.sql"; String initFileName = "/install/db/jeecms-init-2.4.2-final.sql"; //创建数据库 if ("true".equals(isCreateDb)) { Install.createDb(dbHost, dbPort, dbName, dbUser, dbPassword); Install.changeDbCharset(dbHost, dbPort, dbName, dbUser, } else { dbPassword); } //创建表 if ("true".equals(isCreateTable)) { String sqlPath = application.getRealPath(dbFileName); List sqlList = Install.readSql(sqlPath); Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword, sqlList); } //初始化数据 if ("true".equals(isInitData)) { String initPath = application.getRealPath(initFileName); List initList = Install.readSql(initPath); Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword, initList); } //更新配置 Install.updateConfig(dbHost, dbPort, dbName, dbUser, dbPassword, domain, cxtPath, port); //处理数据库配置文件 String dbXmlPath = application.getRealPath(dbXmlFileName); Install .dbXml(dbXmlPath, dbHost, dbPort, dbName, dbUser,
dbPassword); //处理web.xml String webXmlFromPath = application.getRealPath(webXmlFrom); String webXmlToPath = application.getRealPath(webXmlTo); Install.webXml(webXmlFromPath, webXmlToPath); //在 Util 里面 /** * 安装类 * * @author liufang * */ public class Install { dbPort, Exception { public static void dbXml(String fileName, String dbHost, String String dbName, String dbUser, String dbPassword) throws String s = FileUtils.readFileToString(new File(fileName)); s = s.replaceFirst("DB_HOST", dbHost); s = s.replaceFirst("DB_PORT", dbPort); s = s.replaceFirst("DB_NAME", dbName); s = s.replaceFirst("DB_USER", dbUser); s = s.replaceFirst("DB_PASSWORD", dbPassword); FileUtils.writeStringToFile(new File(fileName), s); Exception { + dbName } } public static Connection getConn(String dbHost, String dbPort, String dbName, String dbUser, String dbPassword) throws Class.forName("com.mysql.jdbc.Driver").newInstance(); String connStr = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + "?user=" + dbUser + "&password=" + dbPassword + "&characterEncoding=GBK"; Connection conn = DriverManager.getConnection(connStr); return conn; public static void webXml(String fromFile, String toFile) throws FileUtils.copyFile(new File(fromFile), new File(toFile)); Exception { } /**
* 创建数据库 * * @param dbHost * @param dbName * @param dbPort * @param dbUser * @param dbPassword * @throws Exception */ public static void createDb(String dbHost, String dbPort, String String dbUser, String dbPassword) throws Exception { Class.forName("com.mysql.jdbc.Driver").newInstance();; String connStr = "jdbc:mysql://" + dbHost + ":" + dbPort + dbName, "?user=" + dbUser + "&password=" + dbPassword + "&characterEncoding=GBK"; Connection conn = DriverManager.getConnection(connStr); Statement stat = conn.createStatement(); String sql = "drop database if exists " + dbName; stat.execute(sql); sql = "create database " + dbName + " CHARACTER SET GBK"; stat.execute(sql); stat.close(); conn.close(); public static void changeDbCharset(String dbHost, String dbPort, String dbName, String dbUser, String dbPassword) throws Connection conn = getConn(dbHost, dbPort, dbName, dbUser, Exception { dbPassword); Statement stat = conn.createStatement(); String sql = "ALTER DATABASE " + dbName + " CHARACTER SET GBK"; stat.execute(sql); stat.close(); conn.close(); } } /** * 创建表 *
* @param dbHost * @param dbName * @param dbPort * @param dbUser * @param dbPassword * @param sqlList * @throws Exception */ public static void createTable(String dbHost, String dbPort, String String dbUser, String dbPassword, List sqlList) throws Exception { Connection conn = getConn(dbHost, dbPort, dbName, dbUser, dbName, dbPassword); Statement stat = conn.createStatement(); for (String dllsql : sqlList) { stat.addBatch(dllsql); } stat.executeBatch(); stat.close(); conn.close(); } /** * 更新配置 * * @param dbHost * @param dbName * @param dbPort * @param dbUser * @param dbPassword * @param domain * @param cxtPath * @param port * @throws Exception */ public static void updateConfig(String dbHost, String dbPort, String dbName, String dbUser, String dbPassword, String String cxtPath, String port) throws Exception { Connection conn = getConn(dbHost, dbPort, dbName, dbUser, domain, dbPassword); Statement stat = conn.createStatement(); String sql = "update CORE_WEBSITE set DOMAIN='" + domain + "'";
stat.executeUpdate(sql); sql = "update CORE_GLOBAL set CONTEXT_PATH='" + cxtPath + "',PORT=" + port; stat.executeUpdate(sql); stat.close(); conn.close(); } /** * 读取sql语句。“/*”开头为注释,“;”为sql结束。 * * @param fileName * sql文件地址 * @return list of sql * @throws Exception */ public static List readSql(String fileName) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(fileName), Constants.ENCODING)); List sqlList = new ArrayList(); StringBuilder sqlSb = new StringBuilder(); String s = null; while ((s = br.readLine()) != null) { if (s.startsWith("/*")) { continue; } if (s.endsWith(";")) { sqlSb.append(s); sqlSb.setLength(sqlSb.length() - 1); sqlList.add(sqlSb.toString()); sqlSb.setLength(0); } else { sqlSb.append(s); } } br.close(); return sqlList; } }
jcaptcha 自定义验证码 (略) Xml org.springframework.web.util.IntrospectorCleanupListener< /listener-class> 20 404 /404.html 403 /403.html index.jspa index.do index.html 目录:之一
总共 40 张表 在 Spring 里面可以用这种方式: classpath:/com/jeecms/core/entity/*.hbm.xml classpath:/com/jeecms/cms/entity/*.hbm.xml classpath:/com/jeecms/article/entity/*.hbm.xml classpath:/com/jeecms/download/entity/*.hbm.xml classpath:/com/jeecms/auxiliary/entity/*.hbm.xml 同样 Hibernate 也可以这样: hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect hibernate.show_sql=true hibernate.format_sql=false hibernate.query.substitutions=true 1, false 0 hibernate.jdbc.batch_size=20 hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider hibernate.cache.provider_configuration_file_resource_path=/ehcache-hibernate .xml Spring 事务 Spring 注解@Component、@Repository、@Service、@Controller 区别 Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分 别是:@Repository、@Service 和 @Controller。在目前的 Spring 版本中,这 3 个注释和 @Component 是等效的,但是从注释类的命名上,很容易看出这 3 个注释分别和持久层、 业务层和控制层(Web 层)相对应。虽然目前这 3 个注释和 @Component 相比没有什么 新意,但 Spring 将在以后的版本中为它们添加特殊的功能。所以,如果 Web 应用程序采
分享到:
收藏