I'd like to test my servlet by printing the results to the console. System.out.println does not seen to work for a servlet. Does anyone know how I can achieve this? Main purpose is for debugging at a later stage.
public class GetAllStaff extends HttpServlet {
private static final long serialVersionUID = 1L;
static StaffDAO dao = new StaffDAO();
static ArrayList<Staff> sList = null;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
sList = dao.getAllStaff();
for (int i = 0; i < sList.size(); i++)
{
}
}
You could use
ServletContext context = getServletContext( );
context.log("This is a log item");
The logs are not printed in Eclipse console but can be found at logs folder of servlet container (say Apache Tomcat)
Reference: http://www.tutorialspoint.com/servlets/servlets-debugging.htm
You may want to print everything on a browser with the following code?
PrintWriter out = res.getWriter();
out.println("Some information on the browser...");
PS I tried System.out.println("something");
in my IDE (Intellij), the result showed up in the console.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.