Results 1 to 4 of 4
  1. #1
    adammyth is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Post Servlet basic example

    Hi,

    i am very new on J2EE and trying to learn servlets by following an example described in this link: Server-side Java: Understanding JavaServer Pages Model 2 architecture - JavaWorld

    Unfortunately i am not able to make the example work, i am getting HTTP Status 404 error: The requested resource (/shopping/ShoppingServlet) is not available.

    I am using Tomcat.
    My directory structure is as follows:

    WebContent/EShop.jsp
    WebContent/Cart.jsp
    WebContent/WEB-INF/classes/shopping/ShoppingServlet.class
    WebContent/WEB-INF/classes/shopping/CD.class
    WebContent/META-INF

    And web.xml which is automatically created by eclipse is as follows :

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>WebDev_2</display-name>
    <servlet>
    <description>
    </description>
    <display-name>ShoppingServlet</display-name>
    <servlet-name>ShoppingServlet</servlet-name>
    <servlet-class>
    shopping.ShoppingServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ShoppingServlet</servlet-name>
    <url-pattern>/ShoppingServlet</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    </web-app>


    What is the problem here?

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    366
    Rep Power
    6

    Default

    Quote Originally Posted by adammyth View Post
    Hi,

    Unfortunately i am not able to make the example work, i am getting HTTP Status 404 error: The requested resource (/shopping/ShoppingServlet) is not available.


    ...
    <servlet-mapping>
    <servlet-name>ShoppingServlet</servlet-name>
    <url-pattern>/ShoppingServlet</url-pattern>
    </servlet-mapping>
    ...
    </web-app>


    What is the problem here?
    Be sure your URL mapping is correct.

    Try like:
    http://localhost:8080/application_name/ShoppingServlet

    Are you getting any info from servlet?

  3. #3
    adammyth is offline Member
    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Default

    When i try with http://localhost:8080/WebDev_2/ShoppingServlet

    i get the following error:

    HTTP Status 405 - HTTP method GET is not supported by this URL

    How can i be be sure that my URL mapping is correct?

  4. #4
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    366
    Rep Power
    6

    Default

    In your form :

    ...
    Java Code:
    <form name="shoppingForm" 
       action="[B]/examples/servlet/ShoppingServlet"[/B] 
       method="POST">
    ...

    So there is POST not GET and path is
    /examples/servlet/ShoppingServlet
    not just
    /ShoppingServlet


    Open ShoppingServlet.java code, find doGet() method and add some
    test to console with some
    System.out.println("Hi from doGet() !");
    just to test it.

    So while trying to solve that url mapping
    run ShoppingServlet directly
    and see if you can hit that doGet() you added and message in console.
    That's easiest way to test in whenever you make it.
    So first test GET that you make and then test post from that form.

    still got problems?

Similar Threads

  1. how can i link html+servlet+xml to form servlet
    By balachandarr in forum Java Servlet
    Replies: 0
    Last Post: 04-15-2009, 05:06 PM
  2. Servlet to Servlet connection through URLConnection
    By bsrjavaforum in forum Networking
    Replies: 0
    Last Post: 04-01-2009, 05:12 PM
  3. Replies: 1
    Last Post: 12-02-2008, 01:23 AM
  4. Replies: 0
    Last Post: 08-30-2008, 12:52 PM
  5. Replies: 1
    Last Post: 08-07-2007, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •