setup2.jsp
上传用户:jhtang88
上传日期:2014-01-27
资源大小:28528k
文件大小:5k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html;charset=utf-8" %>
  2. <%@ page import="java.io.*,
  3.  cn.js.fan.db.*,
  4.  cn.js.fan.util.*,
  5.  cn.js.fan.web.*,
  6.  com.redmoon.forum.*,
  7.  org.jdom.*,
  8.                  java.util.*"
  9. %>
  10. <%
  11. XMLConfig cfg = new XMLConfig("config_cws.xml", false, "iso-8859-1");
  12. %>
  13. <title>云网OA安装 - 配置数据库连接</title>
  14. <link rel="stylesheet" type="text/css" href="../common.css">
  15. <table cellpadding="6" cellspacing="0" border="0" width="100%">
  16. <tr>
  17. <td width="1%" valign="top"></td>
  18. <td width="99%" align="center" valign="top">
  19.     <div align="left"><b>欢迎您使用云网OA 版本<%=cfg.get("Application.version")%></b></div>
  20.     <hr size="0">
  21. <%
  22. cfg = new XMLConfig(application.getRealPath("/") + "WEB-INF" + java.io.File.separator + "proxool.xml", true, "iso-8859-1");
  23. Element root = cfg.getRootElement();
  24. Element driverProp = root.getChild("proxool").getChild("driver-properties");
  25. List list = driverProp.getChildren();
  26. Element e_user = (Element)list.get(0);
  27. Element e_pwd = (Element)list.get(1);
  28. String user = e_user.getAttributeValue("value");
  29. String pwd = e_pwd.getAttributeValue("value");
  30. String url = cfg.get("proxool.driver-url");
  31. int beginIndex = url.indexOf("//");
  32. String ip = url.substring(beginIndex + 2, url.indexOf(":", beginIndex));
  33. String database = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("?"));
  34. String port = url.substring(url.lastIndexOf(":")+ 1, url.lastIndexOf("/"));
  35. String maximum_connection_count = cfg.get("proxool.maximum-connection-count");
  36. String op = ParamUtil.get(request, "op");
  37. boolean isValid = false;
  38. if (op.equals("setup")) {
  39. user = ParamUtil.get(request, "user");
  40. ip = ParamUtil.get(request, "ip");
  41. port = ParamUtil.get(request, "port");
  42. database = ParamUtil.get(request, "database");
  43. pwd = ParamUtil.get(request, "pwd");
  44. url = "jdbc:mysql://" + ip + ":" + port + "/" + database + "?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull";
  45. maximum_connection_count = ParamUtil.get(request, "maximum_connection_count");
  46. cfg.set("proxool.driver-url", url);
  47. e_user.setAttribute("value", user);
  48. e_pwd.setAttribute("value", pwd);
  49. cfg.set("proxool.maximum-connection-count", maximum_connection_count);
  50. cfg.writemodify();
  51. Global.init();
  52.     try {
  53. org.logicalcobwebs.proxool.ProxoolFacade.removeAllConnectionPools(5000); 
  54. org.logicalcobwebs.proxool.configuration.JAXPConfigurator.configure(application.getRealPath("/") + "WEB-INF/proxool.xml", false);
  55.     } catch (Exception e) {
  56.      out.print("Problem configuring: " + e.getMessage());
  57. e.printStackTrace();
  58.     }
  59. }
  60. %>
  61. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  62. <form name=form1 action="?op=setup" method=post>
  63.       <tr>
  64.         <td height="24" colspan="2" align="left">配置数据库连接:</td>
  65.         </tr>
  66.       <tr>
  67.         <td height="24" align="right">&nbsp;</td>
  68.         <td><%
  69. if (op.equals("setup")) {
  70. String sql = "select * from redmoonID";
  71. Conn conn = new Conn(Global.defaultDB);
  72. if (conn.getCon()!=null) {
  73. try {
  74. conn.executeQuery(sql);
  75. isValid = true;
  76. }
  77. catch (Exception e) {
  78. out.print(e.getMessage());
  79. }
  80. finally {
  81. if (conn!=null) {
  82. conn.close();
  83. conn = null;
  84. }
  85. }
  86. }
  87. if (!isValid) {
  88. out.print("<font color=red>测试连接失败!请检查连接字符串、用户名和密码是否正确!</font>");
  89. }
  90. else
  91. out.print("<font color=green><b>测试连接成功!</b></font>");
  92. }
  93. %></td>
  94.       </tr>
  95.       <tr>
  96.         <td height="24" align="right">配置文件路径:</td>
  97.         <td><%=application.getRealPath("/") + "WEB-INF" + java.io.File.separator + "proxool.xml"%>&nbsp;&nbsp;&nbsp;(在初始化前,请先将cwbbs.sql导入mysql数据库)</td>
  98.       </tr>
  99. <!--   
  100.       <tr>
  101.         <td height="24" align="right">数据库连接字符串:</td>
  102.         <td><input name="url" value="" size="50"/></td>
  103.       </tr>
  104. -->   
  105.       <tr>
  106.         <td height="24" align="right">用户名:</td>
  107.         <td><input name="user" value="<%=user%>"/></td>
  108.       </tr>
  109.       <tr>
  110.         <td height="24" align="right">密码:</td>
  111.         <td><input type="password" name="pwd" value="<%=pwd%>"/></td>
  112.       </tr>
  113.       <tr>
  114.         <td height="24" align="right"><span class="thead" style="PADDING-LEFT: 10px">主机名:</span></td>
  115.         <td><input name="ip" value="<%=ip%>"/></td>
  116.       </tr>
  117.       <tr>
  118.         <td height="24" align="right"><span class="thead" style="PADDING-LEFT: 10px">端口号:</span></td>
  119.         <td><input name="port" value="<%=port%>" size="8"/></td>
  120.       </tr>
  121.       <tr>
  122.         <td height="24" align="right"><span class="thead" style="PADDING-LEFT: 10px">数据库名:</span></td>
  123.         <td><input name="database" value="<%=database%>"/></td>
  124.       </tr>
  125.       <tr>
  126.         <td height="24" align="right">最大连接数:</td>
  127.         <td><input type="text" name="maximum_connection_count" value="<%=maximum_connection_count%>"/></td>
  128.       </tr>
  129.   </form>
  130.     </table>
  131.     <hr size="0">
  132.     
  133.     <div align="center">
  134.     <input name="button22" type="button" onclick="window.location.href='setup.jsp'" value="上一步" />
  135. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  136. <input type="button" value="连接测试" onClick="form1.submit()">
  137. <%if (isValid) {%>
  138. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  139. <input name="button2" type="button" onclick="window.location.href='setup3.jsp'" value="下一步" /></td>
  140. <%}%>
  141. </tr>
  142. </table>