?
Solved

Help! tomcat 5.5 does'nt run my servlet.

Posted on 2006-10-19
12
Medium Priority
?
329 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
[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
  • 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
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 
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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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