• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to run servlets

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i am not able to run servlet..i am able to compile them but
when i run it in explorer i get error 404...
please help....

Thanks in advance
Anubha.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular please see:
TellTheDetails

In particular we would need to see:
  • You servelet declaration (in web.xml)
  • Your servlet mapping (also in web.xml)
  • The URL that you're using (either in your browser's address window, your hyperlink's href attribute or your form's action attribute)

  • And anything else you think might help someone solve this problem.
    Again, welcome to JavaRanch and good luck with your question.
    -Ben
     
    Rancher
    Posts: 43081
    77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Where is the servlet class file located? Which URL are you trying to access? How is the servlet mapped in the web.xml file - post the servlet and servlet-mapping elements.
     
    anubha goel
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hii,
    my web.xml file is:

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE web-app (View Source for full doctype...)>
    <web-app>
    <servlet>
    <servlet-name>colour</servlet-name>
    <servlet-class>colour</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>colour</servlet-name>
    <url-pattern>servlet/colour</url-pattern>
    </servlet-mapping>
    </web-app>
    -------------------
    i hav placed my class file in: C:\apache-tomcat-5.5.23\webapps\anu\WEB-INF\classes\colour

    -----------------------
    i am trying to access my servlet through following URL:
    http://localhost:8080/anu/col.html
    -------------------------------
    my java servlet is :
    COLOUR.JAVA

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class colour extends HttpServlet
    {
    public void service(HttpServletRequest rq,HttpServletResponse rs)throws ServletException, IOException
    {
    PrintWriter out=rs.getWriter();
    String s=rq.getParameter("colour");
    out.println("<body bgcolor="+s+"><H1><font color=red>this is get parameter example</font></H1></body>");
    out.close();
    }
    }
    -----------------------
    my html file is:
    COL.HTML

    <form action="http://localhost:8080/anu/colour" method="Post">
    name of color<input type=text name=color><BR>
    <input type=submit value=set>
    </form>

    Thanks And Regards,
    Anubha.
     
    Ulf Dittmer
    Rancher
    Posts: 43081
    77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    <url-pattern>servlet/colour</url-pattern>


    That should be

    <url-pattern>colour</url-pattern>



    Also, the class file should be in "C:\apache-tomcat-5.5.23\webapps\anu\WEB-INF\classes", not in "C:\apache-tomcat-5.5.23\webapps\anu\WEB-INF\classes\colour".
     
    Ranch Hand
    Posts: 3389
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
  • Check the url-pattern you have configured in web.xml is different than that of what you access at runtime. Make sure they both are same.
  • The class what you have specified is of default package. Be careful in that case where your actual .class files reside. Have a look at that as well.


  • [ July 30, 2007: Message edited by: Raghavan Muthu ]
     
    anubha goel
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,
    i made all the changes but still getting the same error-404....i am too buged up..
    please help...

    Thanks and Regards,
    Anubha.
    [ July 30, 2007: Message edited by: anubha goel ]
     
    Author and all-around good cowpoke
    Posts: 13078
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    <servlet-class>colour</servlet-class>



    ALL java classes used in servlets should be in a package and located under \classes using the package name. Failure to do so results in exactly what you are seeing - the servlet container has its own idea of what the "current" directory is.

    Bill
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3389
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yeah, thats correct as william Brodgen said.

    Its always better to keep your files in some specific packages rather than leaving it to the default packages!

    Thanks for pointing out Bill.
     
    Ranch Hand
    Posts: 218
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi anu,

    See this web.xml

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtds/web-app_2_3.dtd">

    <web-app>
    <servlet>
    <servlet-name>colour</servlet-name>
    <servlet-class>colour</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>colour</servlet-name>
    <url-pattern>/colour</url-pattern>
    </servlet-mapping>
    </web-app>


    You hould start the url pattern with a / unless its something like

    so it should be /colour and not just color

    Some other suggestions ( These are not causing any problems but just some suggestions)

    -> In the html the action can be just colour and you need not put the whole
    path.

    -> I would suggest you to use use camel case for the class name.
    keep it Colour and not color.

    -> Make sure web.xml is in <webapp>/WEB-INF and class file in
    <webapp>/WEB-INF/classes

    everything else looks fine. I think adding a / in the
    <url-pattern>/colour</url-pattern> tag should be ok.

    Amol..
     
    anubha goel
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hii,
    i tried all solutions but nothing is working...
    can somone telme an example so that i can try to run that on my system...
    it mite be helpful...

    Thanks & Regards,
    Anubha.
     
    Amol Nayak
    Ranch Hand
    Posts: 218
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi anu.

    Thats strange, do one thing can you mail me the zip of the files you are using. Let me go through it and see whats goin wrong..

    mail to amolnayak311@gmail.com..

    Amol..
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser VI Editor Redhat
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by anubha goel:
    hii,
    i tried all solutions but nothing is working...
    can somone telme an example so that i can try to run that on my system...
    it mite be helpful...

    Thanks & Regards,
    Anubha.



    There is a very simple "hello, world" servlet on my site.
    Look for Simple Servlet.
    http://simple.souther.us
     
    anubha goel
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,
    thanks a lot all of you and specially Amol.
    my servlet is running successfully now.

    Thanks & Regards,
    Anubha.
     
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Amol Nayak:
    mail to amolnayak311@gmail.com..



    Amol, in the future please do not take the conversation out of the forums. Please read this for more information.
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser VI Editor Redhat
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by anubha goel:
    Hi,
    thanks a lot all of you and specially Amol.
    my servlet is running successfully now.

    Thanks & Regards,
    Anubha.



    What was it?
     
    Amol Nayak
    Ranch Hand
    Posts: 218
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Bear, i am aware of it.. I told her to mail me the files so that i can take a look at it.

    It was the problem with web.xml file.. I have already posted the web.xml she needs to use..
     
    anubha goel
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,
    i am really very sorry if i prohibited any rules...

    Thanks & Regards,
    Anubha.
     
    Ranch Hand
    Posts: 105
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi there,

    I gained alot from this post, especially that I suffered similar problems many times. I have a final question though, assuming that the servlet classes reside in the default package, or folder, "classes/", what are the urls that correspond to the following mappings, particularly when trying to invoke either servlet through a relative url:



    and


    Thank you very much in advance
    Hatim
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    assuming that the servlet classes reside in the default package



    Such a practice is strongly discouraged.
    reply
      Bookmark Topic Watch Topic
    • New Topic