Consider the following snippet
public static JSONObject getStudentDetails() throws Exception {
//returns the details as json
}
public static JSONObject getDepartmentDetails(String department_id) throws Exception {
//returns the details as json
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws Exception {
JSONObject json1 = getStudentDetails();
String name = json1.getString(“name”);
String role_number = json1.getString(“role_number”);
String department_id = json1.getStrring(“department_id”);
//and goes on - to get all student details
JSONObject json2 = getDepartmentDetails(department_id);
String department_hod = json2.getString(“department_hod”);
String department_name = json2.getString(“department_name”);
String department_block = json2.getString(“department_block”);
//and goes on - till i get all the department details
//Followed by main action to be performed
}
In the above code for most of the case i am likely to call an util method which returns a json object which i am using in my doGet/doPost method. So most part of my code in my doPost/doGet is like to fetch values from json object with getString. Is there any better way to organise the above snippet?
Aucun commentaire:
Enregistrer un commentaire