ajax|j2ee| Agency management org.jsp files are used to ServerBuilding a bridge between the class running Java and the foreground web page . The interface function of taking to the middleware .
Here, analyze some of the code:
<%@ 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.*"%> The above is mainly referencing some Java classes <% try{ Request.setcharacterencoding ("GBK"); Document doc = xmltool.createdocumentfromrequest (request); Create a Document object for a Web-facing document request Connection conn = Conntool.getconnectionfrompool (); Gets the requested method name String Mode=request.getparameter ("mode"); OUT.PRINTLN ("CCC"); Read the organization tree data if there are no other parameters in the method 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")) { If it's the Createorg method, create an organization int parentorgid = Integer.parseint (Request.getparameter ("Parentorgid")); Take out the first argument passed Parentorgid int orgid = orgmanager.createorg (PARENTORGID, conn); Call the Createorg method of the Orgmanager class to create an organization Out.println (OrgID); return results } Conn.close (); } catch (Exception e) { E.printstacktrace (); } %> |
VI. Implementation of background data
1. Definition of data structure
Here, we have three main tables . One is the organization chart, one is People table person, an organization staff association table Orgperson . Organization Chart has orgcode (organization code), OrgName (organization name), ORGID (organization ID), PARENTORGID (parent ID) . Staff table has Personcode (personnel code), PersonName (person name), sex (gender), PERSONID (Person ID) . Orgperson table has OrgID, personId .
2. DatabaseThe connection
Web applications often use MySQL as a background Database, this is because MySQL is simple and efficient . Here we also use MySQL as DatabaseJDBC Connection in Java Database . Here is the connection DatabaseThe code:
public static Connection Getconnectionfrompool () throws Exception { Context ctx = new InitialContext (); DataSource ds = (DataSource) ctx.lookup ("Java:/erpds"); return Ds.getconnection (); }
/** * Fetch Database link Object * @return Connection database linked objects * @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; } */ |
3. Implementation of the business logic layer
Background development We use Java classes to implement . Here we have developed a orgnew package, the class name is Orgmanager. This class encapsulates the methods associated with database operations . the correctness of the program can be debugged by main .