In this example, a servlet provides outward query of employee information in json format. Servlet accesses employee table in the database and saves employee information as follows:
doGet function of servlet receives employee id strings of json format, queries corresponding employee information through the database and generates employee information list in json format and then returns it. Process of reading the database and generating employee information is omitted in the following code: protected void doGet(HttpServletRequestreq, HttpServletResponseresp) throws Servlet Exception, IOException {
// TODO Auto-generated method stub
String inputString=(String) req.getParameter("input");
//inputString input value is:"[{EID:8},{EID:32},{EID:44}]";
if (inputString==null) inputString="";
String outputString ="";
{...}//code for querying the database through inputString and generating outputSring is omitted here
// the generated outputString
//"[{EID:8,NAME:"Megan",SURNAME:"Wilson",GENDER:"F",STATE:\...";
resp.getOutputStream().println(outputString);
resp.setContentType("text/json; charset=GBK");
}
The following code can be used for esProc to access this http servlet:
A1: Define the input parameter to be submitted to servlet, i.e. the employeeid list
in json format.
A2: Define httpfile objects, URL
is http://localhost:8080/demo/testServlet?input=[{EID:8},{EID:32},{EID:44}].
A3: Import A2, the result returned by http file objects.
A4: Parse by rows the json format
information of each employee, and create a sequence.
A5: Compute on the table sequence in A4 and combine SURNAME and NAME
into FULLNAME.
没有评论:
发表评论