Solved

Help! tomcat 5.5 does'nt run my servlet.

Posted on 2006-10-19
12
317 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
ID: 17764315
>>"public class A implements Servlet"
should that be HttpServlet?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 17764342
> 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
ID: 17764343
i'm not extending HttpServlet, i'm implenting Servlet interface. so thats why i used it
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 400 total points
ID: 17764350
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
ID: 17764356
i'll check
0
 

Author Comment

by:shilpi84
ID: 17764362
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
 
LVL 16

Accepted Solution

by:
suprapto45 earned 400 total points
ID: 17764365
>>"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
ID: 17764395
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
ID: 17764425
> a blank page shows up.

what exactly do u expect?
0
 

Author Comment

by:shilpi84
ID: 17764429
thanks suprapto45!
0
 

Author Comment

by:shilpi84
ID: 17764433
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
ID: 17771577
Glad I could help :).
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
starter POM and spring-boot-starter,  spring-boot-web 2 58
egit plugin on eclipse 8 64
Groovy problem when using SOAPUI : DispatchException occurred 7 46
ejb on wildfly 5 20
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 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