请问一下一个问题,
这么功能主要是传订单资讯到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/>");
}
}
}