Using AJAX+J2EE to develop organizational management systems (4)

Source: Internet
Author: User
Tags object integer sql mysql return string sybase
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
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");
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:";
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 .

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.