Issue
I'm new to Servlets I just trying to print a simple Html tag inside servlet response but I dunno why it doesn't print in Browser. it just print the String without getting the Html tags.
Here is the code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Hi All");
PrintWriter out =response.getWriter();
out.println("<h2>Please complete our Customer Survey</h2>");
}
}
**Out Put print as **
<h2>Please complete our Customer Survey</h2>
Please let me know how to fix this Thanks.
Solution
ContentType must be set. Try this.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Hi All");
response.setContentType("text/html; charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<h2>Please complete our Customer Survey</h2>");
}
Answered By - John Coffey