Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help! tomcat 5.5 does'nt run my servlet.

Posted on 2006-10-19
12
Medium Priority
?
330 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
Independent Software Vendors: 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
A solution for Fortify Path Manipulation.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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