請問一下一個問題,
這麼功能主要是傳訂單資訊到servlet, 我這邊有判斷p_id(訂單如果為0)則顯示參數錯誤
但我發現如果我的URL為 : http://localhost:8080/testDemo/servlet
也就士都不帶任何參數, 這時候在使用p_id.length()就會發生異常,
也就是我的code會停在呼叫pid_length的那一行, 但我這時候也捕捉不到錯誤
(catch也沒印出錯誤) ~ 麻煩各位 謝謝
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String pid = request.getParameter("p_id");
String uid = request.getParameter("uid");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body>");
if(pid.length() != 0) {
out.println("<div>訂單資訊 pid : " + pid + " uid : "+ uid + " length : " + pid.length() +"</div>");
} else {
out.println("測試");
}
out.println("</body>");
out.println("</html>");
} catch (Exception e) {
response.getWriter().write(e.getMessage());
StackTraceElement[] trace = e.getStackTrace();
for(int i = 0 ; i < trace.length ; i++){
response.getWriter().write(trace[i].toString());
response.getWriter().write("<br/>");
}
}
}