servlet层:
package servlet;
import dao.tabledao;
import net.sf.json.JSONArray;
import org.json.JSONObject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
@WebServlet("/sqlServlet")
public class sqlServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String colname=(String)request.getSession().getAttribute("colname");
PrintWriter out=response.getWriter();
JSONObject jsonObject=new JSONObject();
jsonObject.put("code",0);
jsonObject.put("msg","");
jsonObject.put("count",1);
String sql="select * from col where table_name = '" + colname+"' ";
System.out.println(sql);
JSONArray result=null;
try{
tabledao he=new tabledao();
result = JSONArray.fromObject(he.collist(sql));
}catch(SQLException ex)
{
ex.printStackTrace();
}
jsonObject.put("data",result);
System.out.println(jsonObject.toString());
out.println(jsonObject.toString());
out.flush();
out.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
}