Solved

No output from servlet

Posted on 2011-02-27
3
498 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countPairs challenge 7 74
strCount chalenge 3 82
eclipse formatting 6 91
couple of eclipse 5 38
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
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.

809 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