package com.hzzq; import com.hzzq.Config; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; public class GetBMTree extends HttpServlet { public void destroy() { super.destroy(); } public Connection getConnection(String p_dbname) throws Exception { String prefix = this.getServletContext().getRealPath("/"); if(prefix == null) { prefix = System.getProperty("user.home"); if(prefix == null) { prefix = "."; } if(prefix.charAt(prefix.length() - 1) != File.separatorChar) { prefix = prefix + File.separatorChar; } } if(prefix.charAt(prefix.length() - 1) != File.separatorChar) { prefix = prefix + File.separatorChar; } Config.WebModuleRootPath = prefix; Config.init(); String s_dbname = Config.DB_NAME; if(p_dbname != "") { ; } String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; Class.forName(driver); String url = "jdbc:sqlserver://" + Config.DB_IP + ":" + Config.DB_PORT + ";DatabaseName=" + Config.DB_NAME + ";user=" + Config.DB_USER + ";password=" + Config.DB_PASSWORD; Connection conn = DriverManager.getConnection(url, Config.DB_USER, Config.DB_PASSWORD); return conn; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); String s_companyid = session.getAttribute("companyid").toString(); Connection conn = null; String outstr = "[empty]"; try { conn = this.getConnection(""); Statement out = conn.createStatement(); String sql = "SELECT bh as Id,mc,p_bh FROM bx_materielClass where lx=\'9\' and companyId=\'" + s_companyid + "\' order by xh"; System.out.println(sql); ResultSet rs = out.executeQuery(sql); if(rs == null) { outstr = "[empty]"; } else { for(outstr = "["; rs.next(); outstr = outstr + "{\'id\':\'" + rs.getString("Id") + "\',\'text\':\'" + rs.getString("mc") + "\',\'pid\':\'" + rs.getString("p_bh") + "\'},") { ; } outstr = outstr.substring(0, outstr.length() - 1); outstr = outstr + "]"; } System.out.println(outstr); rs.close(); } catch (Exception var18) { var18.printStackTrace(); } finally { try { conn.close(); } catch (SQLException var17) { var17.printStackTrace(); } } response.setContentType("text/html;charset=gbk"); PrintWriter out1 = response.getWriter(); out1.println(outstr); out1.flush(); out1.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(""); out.println(""); out.println("