Debug trong Servlet | 27 bài hướng dẫn Servlet miễn phí hay nhất debug trong servlet

4 96 0
Debug trong Servlet | 27 bài hướng dẫn Servlet miễn phí hay nhất debug trong servlet

Đang tải... (xem toàn văn)

Thông tin tài liệu

http://vietjack.com/  servlets/index.jsp                                                                                                              Copyright  ©  vietjack.com     Debug Servlet Nó khó để test/debug Servlet Các Servlet bao gồm lượng lớn tương tác Client/Server, việc tạo Error hồn tồn Sau số gợi ý giúp bạn việc debug servlet Phương thức System.out.printIn() Phương thức System.out.printIn() dễ để sử dụng Marker để kiểm tra có hay khơng phần code thực thi khơng Chúng ta in giá trị biến Ngồi ra: • Vì đối tượng System phần đối tượng Core Java, sử dụng đâu mà không cần cài đặt lớp bổ sung Nó bao gồm Servlet, JSP, RMI, EJB's, ordinary Beans, class, standalone application • So sánh với việc dừng Breakpoint, việc write tới System.out không gây trở ngại nhiều tới luồng thực thi thông thường ứng dụng, mà làm cho đáng quý Sau cú pháp System.out.printIn(): System.out.println("Debugging message"); Tất message tạo cú pháp log log file Web Server Log message Để log tất thông báo debug, warning, error bạn nên sử dụng phương thức logging chuẩn Chúng sử dụng log4J để log tất message Servlet API cung cấp cách đơn giản để output thông tin sử dụng phương thức log() sau: // Import required java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ContextLog extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, String par = request.getParameter("par1"); java.io.IOException { //Call the two ServletContext.log methods ServletContext context = getServletContext( ); if (par == null || par.equals("")) //log version with Throwable http://vietjack.com/                                                                                                                              Trang  chia  sẻ  các  bài  học  online  miễn  phí  Page  1   http://vietjack.com/  servlets/index.jsp                                                                                                              Copyright  ©  vietjack.com     parameter context.log("No message received:", IllegalStateException("Missing parameter")); new else context.log("Here is the visitor's message: " + par); response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter( ); String title = "Context Log"; = "\n"; out.println(docType + "" + title + "\n" + bgcolor=\"#f0f0f0\">\n" + String docType "\n" + "

Ngày đăng: 02/12/2017, 22:24

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan