我正在尝试实施TrueMD API,如http://www.truemd.in/api/documentation#javasdk所述。 我下载了TrueMD.jar并使用Netbeans8.0添加到java web servlet应用程序的库中。我得到了药物建议,但没有得到他们的详细信息。我尝试了以下代码:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String drugdetail = request.getParameter("drug");
TrueMDAPI.key="3abb58c093fd817e9cddae75b3de2b";
try{
Medicine medicine= TrueMDAPI.getMedicineData(drugdetail);
printMedicine(medicine);
}finally {
out.close();
}
}
private static void printMedicine(Medicine medicine){
System.out.println("manufacturer :"+medicine.getManufacturer());
System.out.println("brand :"+medicine.getBrand());
System.out.println("category :"+medicine.getCategory());
System.out.println("d_class :"+medicine.getDClass());
System.out.println("unit_type :"+medicine.getUnitType());
System.out.println("unit_qty :"+medicine.getUnitQty());
System.out.println("package_type :"+medicine.getPackageType());
System.out.println("package_qty :"+medicine.getPackageQty());
System.out.println("package_price :"+medicine.getPackagePrice());
System.out.println("unit_price :"+medicine.getUnitPrice());
System.out.println("generic_id :"+medicine.getGenericId());
}
我请你帮我找到问题所在。提前谢谢。
答案 0 :(得分:0)
在这段代码之前
try{
Medicine medicine= TrueMDAPI.getMedicineData(drugdetail);
printMedicine(medicine);
}finally {
out.close();
}
尝试粘贴:
try {
drugdetail = URLEncoder.encode(drugdetail, "UTF-8");
} catch (UnsupportedEncodingException ignored) {
// Can be safely ignored because UTF-8 is always supported
}
我希望这会有所帮助。