Solved

Help! tomcat 5.5 does'nt run my servlet.

Posted on 2006-10-19
12
310 Views
Last Modified: 2013-11-24
hi
i made servlet program:
________________________________
//A.java
import javax.servlet.*;
import java.util.Enumeration;
import java.io.IOException;

public class A implements Servlet
{
 public void init(ServletConfig c) throws ServletException
 {
   System.out.println("test1");
   Enumeration parameters=c.getInitParameterNames();
   while(parameters.hasMoreElements())
   {
        System.out.println("test2");
        String p=(String)parameters.nextElement();
        System.out.println("parameter name :"+ p);
        System.out.println("parameter value :"+c.getInitParameter(p));
   }
 }

 public void destroy(){}
 public void service(ServletRequest s,ServletResponse r) throws ServletException,IOException{}
 public String getServletInfo()
 {
   return null;
 }
 public ServletConfig getServletConfig()
 {
    return null;
 }
}
----------------------------------------------------

compiled it and put it in   c:\tomcat\webapps\h\WEB-INF\classes\     folder
i made the following web.xml and its in the folder-      c:\tomcat\webapps\h\WEB-INF\
------------------------------------------------------
<web-app>
  <servlet>
    <servlet-name>A</servlet-name>
    <servlet-class>A</servlet-class>
    <init-param>
      <param-name>admin</param-name>
      <param-value>ad@max</param-value>
    </init-param>
    <init-param>
      <param-name>number</param-name>
      <param-value>233</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>A</servlet-name>
    <url-pattern>/A</url-pattern>
  </servlet-mapping>

</web-app>
--------------------------------------------------------

now when i enter - http://localhost:8080/h/A

a blank page shows up.
tomcat is running fine and i've run another servlet program before which ran properly.

please help...
0
Comment
Question by:shilpi84
  • 5
  • 5
  • 2
12 Comments
 
LVL 16

Expert Comment

by:suprapto45
Comment Utility
>>"public class A implements Servlet"
should that be HttpServlet?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
Comment Utility
> should that be HttpServlet?

yep, and 'extends'

When a page won'ty load checking the logs is always worth a go. Will often point to the reason
0
 

Author Comment

by:shilpi84
Comment Utility
i'm not extending HttpServlet, i'm implenting Servlet interface. so thats why i used it
0
 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 400 total points
Comment Utility
Ok,

Then do you get any log in your Tomcat console?

>>"        System.out.println("test2");
        String p=(String)parameters.nextElement();
        System.out.println("parameter name :"+ p);
        System.out.println("parameter value :"+c.getInitParameter(p));
"
0
 

Author Comment

by:shilpi84
Comment Utility
i'll check
0
 

Author Comment

by:shilpi84
Comment Utility
these are the logs:

localhost.2006-10-19_____________________________________

Oct 19, 2006 3:31:11 PM org.apache.catalina.core.ApplicationContext log
INFO: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
Oct 19, 2006 3:31:11 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Oct 19, 2006 3:31:11 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Oct 19, 2006 3:31:12 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Oct 19, 2006 3:31:12 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
_____________________________________________________________


stdout_20061019_______________________________________________

test1
test2
parameter name :admin
parameter value :ad@max
test2
parameter name :number
parameter value :233
_____________________________________________________________

every other log is empty
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 16

Accepted Solution

by:
suprapto45 earned 400 total points
Comment Utility
>>"test1
test2
parameter name :admin
parameter value :ad@max
test2
parameter name :number
parameter value :233"

Then it works. It means that your Servlet works. Why it does not load any page? Because you did not specify one. If you want your Servlet to open up another page (JSP), then use what objects recommend, extends HttpServlet and use either redirect or RequestDispatcher to open the JSP.
0
 
LVL 16

Expert Comment

by:suprapto45
Comment Utility
I need to leave now. If you have any questions, I hope that objects can (definitely, he is genius here ;) ) help you.

David
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> a blank page shows up.

what exactly do u expect?
0
 

Author Comment

by:shilpi84
Comment Utility
thanks suprapto45!
0
 

Author Comment

by:shilpi84
Comment Utility
objects i now understood why there is no output i didnt know that the output goes to a log or console when one implents Servlet interface.
0
 
LVL 16

Expert Comment

by:suprapto45
Comment Utility
Glad I could help :).
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

771 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

10 Experts available now in Live!

Get 1:1 Help Now