首页 > 应用开发 > IT综合 > AJAX+J2EE开发组织机构管理系统(5)
五、数据接口的实现(见Org.jpg文件)
Org.JSP文件用来在服务器上运行Java的类与前台web页之间架起一座桥。取到中间件的接口作用。
这里分析部分代码:
| <%@ page contentType="text/html; charset=GBK" %> <%@ page import="java.sql.*" %> <%@ page import="javax.naming.*" %> <%@ page import="javax.sql.*" %> <%@ page import="tool.*" %> <%@ page import="orgNew.*" %> <%@ page import="org.w3c.dom.*" %> //上面主要是引用一些java类 <% try{ //request.setCharacterEncoding("GBK"); Document doc = XmlTool.createDocumentFromRequest(request); //建立web面文档请求的文档对象 Connection conn = ConnTool.getConnectionFromPool(); //获取请求的方法名 String mode=request.getParameter("mode"); //out.println("ccc"); //如果方法中没有其它参数则读取组织树数据 if(mode == null){ /* int OrgId = Integer.parseInt(request.getParameter("id")); String str = orgManager.getChildOrg(OrgId, conn); out.println(str); */ String str = orgManager.getTree(conn); //out.println(str); out.println(str); }else if(mode.equals("createOrg")){ //如果是createOrg方法则建立一个组织 int parentOrgId = Integer.parseInt(request.getParameter("parentOrgId")); //取出传递来的第一个参数parentOrgId int OrgId = orgManager.createOrg(parentOrgId, conn); //调用orgManager 类的createOrg方法来建立一个组织 out.println(OrgId); //返回结果 } conn.close(); } catch(Exception e){ e.printStackTrace(); } %> |
| public static Connection getConnectionFromPool() throws Exception { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:/erpds"); return ds.getConnection(); } /** * 取数据库链接对象 * @return Connection 数据库链接对象 * @throws Exception */ /* public static Connection getDirectConnection() throws Exception { Class.forName("com.sybase.jdbc2.jdbc.SybDriver"); String url = "jdbc:sybase:Tds:19.64.13.16:4100/wydb?charset=iso_1"; String user = "sa"; String password = "2860008"; Connection conn = DriverManager.getConnection(url, user, password); return conn; } */ |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7839366/viewspace-920191/ ,如需转载,请注明出处,否则将追究法律责任。