Solved

No output from servlet

Posted on 2011-02-27
3
496 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
Comment Utility
Remove the method:

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

Author Closing Comment

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

Thanks.
0
 
LVL 9

Expert Comment

by:ioanton
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

744 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

18 Experts available now in Live!

Get 1:1 Help Now