Solved

No output from servlet

Posted on 2011-02-27
3
497 Views
Last Modified: 2013-11-24
I have wriiten one web project the JSP are working fine.
The call to servlet call is abole to show result on console but there is no output on browser.
I can see "helloHereandhere" in my console window.
Please help. here is the code of servlet.
package SecureLogin;

import java.io.*;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;

/**
 * Servlet implementation class SecureCredentials
 */
public class SecureCredentials extends HttpServlet {
      private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SecureCredentials() {
        super();
        System.out.println("helloHereandhere");
        // TODO Auto-generated constructor stub
    }

      /**
       * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
       */
      protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            
      }
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {      
                   
            //HttpSession session = request.getSession();            
            //RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");      
            //dispatcher.forward(request, response);            
      }
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            
             PrintWriter out= response.getWriter();
            StringBuffer sb = new StringBuffer();
            out.println("<html><body>");
            out.println("<h1> Post hello 1 from login servlet</h1>");
            out.println("<p>for login click here</p>");
            sb.append("<UL>\n");
            sb.append("  <LI>param1: ");
            sb.append(request.getParameter("username") + "\n");
            sb.append("  <LI>param2: ");
            sb.append(request.getParameter("password") + "\n");
            sb.append("</UL>\n" );
            out.println("</body></html>");
            //this.doGet(request, response);
            /* out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
                                        "Transitional//EN\">\n" +
                "<HTML>\n" +
                "<HEAD><TITLE>Hello WWW</TITLE></HEAD>\n" +
                "<BODY>\n" +
                "<H1>Hello WWW</H1>\n" +
                "</BODY></HTML>"); */
            out.println(sb);
            out.close();
            }

}


0
Comment
Question by:SD1234
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
ioanton earned 30 total points
ID: 34993035
Remove the method:

      protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           
      }
0
 

Author Closing Comment

by:SD1234
ID: 34993315
Thanks.
It worked.
Can you please help me understand why that method was stopping the ourput?

Thanks.
0
 
LVL 9

Expert Comment

by:ioanton
ID: 34994742
The service() method handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type. It is implemented by the base class (HttpServlet). If you want to override it (which is rarely needed), you must provide the appropriate code for dispatching requests to handler methods (e.g. doPost, doGet...). What you have actually done is an override without any line of code, so that the method does nothing (note that the service() method in the base class is not called anymore in your case).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now