Solved

No output from servlet

Posted on 2011-02-27
3
501 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Stack Overflow Podcast - Frustrating Miracles

In this podcast, Stack Overflow interviewed Linux Academy CEO/Founder, Anthony James, and got his developer story!

"Follow your passion, be prepared to work hard and sacrifice, and, above all, don't let anyone limit your dreams."  - Donovan Bailey

Question has a verified solution.

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

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.
Suggested Courses

635 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