#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    67
    Rep Power
    0

    Smile Inserting html code in servlets


    default way i have seen is
    Code:
     response.setContentType("text/html; charset=UTF-8");
          // 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
          try {
             out.println("<!DOCTYPE html>");
             out.println("<html><head>");
             out.println("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
             out.println("<title>Echo Servlet</title></head>");
             out.println("<body><h2>You have enter</h2>");
    }....
    but is there any alternative way i dont want to go line by line and write out.println everywhere..... its quite disgusting....any ideas?
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1712
    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.

IMN logo majestic logo threadwatch logo seochat tools logo