Solved

No output from servlet

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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse formatting 6 128
arguments to jar 5 44
What kind of framework must i use to do that ? 2 48
eclipse console opening separately 2 50
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…
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.

738 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