1 Replies - 4813 Views - Last Post: 21 August 2012 - 06:54 AM

#1 rjohn5854  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 172
  • Joined: 04-October 11

Basic Servlets HTML display issue

Posted 21 August 2012 - 06:19 AM

I wrote down some HTML code in a servlet doGet Method. But, when i run it on the server, it gets displayed on the titlebar of the browser and the page is empty.

Can someone take a look at my code and correct me.



import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletDemo
 */
	//Url Patterns.
@WebServlet("/TestingServlets")
public class TestingServlets extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestingServlets() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter write = response.getWriter();
		
		write.println("<html>");
		write.println("<head><title>Servlets Demo <title></head>");
		write.println("<body>");
		write.println("<h2>Displayed using servlets</h2>");
		write.println("</body></html>");

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}






<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>HelloJavaWeb</display-name>
 
  <servlet>
    <servlet-name>TestingServlets</servlet-name>
    <servlet-class>TestingServlets</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>TestingServlets</servlet-name>
    <url-pattern>/TestingServlets</url-pattern>
  </servlet-mapping>
</web-app>


This post has been edited by rjohn5854: 21 August 2012 - 06:29 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Basic Servlets HTML display issue

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,993
  • Joined: 20-September 08

Re: Basic Servlets HTML display issue

Posted 21 August 2012 - 06:54 AM

Let us know what it says in the log file of whatever servlet container you're using.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1