February 3rd, 2013, 01:57 AM
Inserting html code in servlets
default way i have seen is
but is there any alternative way i dont want to go line by line and write out.println everywhere..... its quite disgusting....any ideas?
// Allocate a output writer to write the response message into the network socket
PrintWriter out = response.getWriter();
// Write the response message, in an HTML page
out.println("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
out.println("<body><h2>You have enter</h2>");
February 4th, 2013, 03:49 PM
Are you familiar with JSP's?
Basically you should avoid putting anything that is directly display related in a Servlet and have the JSP do the display work. If you need to have dynamic stuff either code it in the JSP (but don't go the other way where your JSP contains code logic) or use a Servlet with, for example, data in the session, to get your data out.