?
Solved

Help! tomcat 5.5 does'nt run my servlet.

Posted on 2006-10-19
12
Medium Priority
?
332 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 400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 1600 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 1600 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

840 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