Porting single servlet example to NetBeans 6.1

Discussion in 'Java' started by Kurt, Jul 20, 2008.

  1. Kurt

    Kurt Guest

    Greetings;



    Specifics:

    OS: Win XP PRO
    App Serv: Tomcat 5.5
    Netbeans: 6.1

    Issue: I am trying to port a simple single servlet from the first
    example in Head First Servlets and JSP 2nd Edition to Netbeans 6.1.

    This example works fine when I deploy it manually under Tomcat.
    However, I am getting a 404 error looking for /Beer-v1/selectBeer.do
    when I try to run the version built and deployed with Netbeans.


    Working structure under tomcat\webapps\Beer-v1 directory

    WEB-INF
    †€€€classes
    „€€€com
    „€€€example
    †€€€model
    „€€€web
    „€€€lib


    Files present;

    \Beer-v1\form.html
    \Beer-v1\result.jsp
    \Beer-v1\WEB-INF\web.xml
    \Beer-v1\WEB-INF\classes\com\example\web\BeerSelect.class

    Non Working directory under Netbeans:

    C:\java\projects\Beer-v1>
    †€€€build
    „€€€web
    †€€€META-INF
    „€€€WEB-INF
    „€€€classes
    „€€€com
    „€€€example
    „€€€web
    †€€€dist
    †€€€nbproject
    „€€€private
    †€€€src
    †€€€conf
    „€€€java
    „€€€com
    „€€€example
    „€€€web
    †€€€test
    „€€€web
    †€€€META-INF
    „€€€WEB-INF


    File present:

    \Beer-v1\build\web\index.html
    \Beer-v1\build\web\META-INF\context.xml
    \Beer-v1\build\web\META-INF\MANIFEST.MF
    \Beer-v1\build\web\WEB-INF\web.xml
    \Beer-v1\build\web\WEB-INF\classes\com\example\web\BeerSelect.class
    \Beer-v1\build\web\WEB-INF\classes\com\example\web\result.jsp
    \Beer-v1\dist\Beer-v1.war
    \Beer-v1\nbproject\ant-deploy.xml
    \Beer-v1\nbproject\build-impl.xml
    \Beer-v1\nbproject\genfiles.properties
    \Beer-v1\nbproject\private
    \Beer-v1\nbproject\project.properties
    \Beer-v1\nbproject\project.xml
    \Beer-v1\nbproject\private\private.properties
    \Beer-v1\src\conf\MANIFEST.MF
    \Beer-v1\src\java\com
    \Beer-v1\src\java\com\example\web\BeerSelect.java
    \Beer-v1\src\java\com\example\web\result.jsp
    \Beer-v1\web\index.html
    \Beer-v1\web\META-INF\context.xml
    \Beer-v1\web\WEB-INF\web.xml


    Contents of web.xml


    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 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">
    <session-config>
    <session-timeout>
    30
    </session-timeout>
    </session-config>
    <servlet>
    <servlet-name>Ch3 Beer</servlet-name>
    <servlet-class>com.example.web.BeerSelect</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Ch3 Beer</servlet-name>
    <url-pattern>/SelectBeer.do</url-pattern>
    </servlet-mapping>
    </web-app>


    Contents of index.html and form.html (They are the same, just two
    different names so I can test the manual build and nb build):


    <html>
    <body>
    <h1 align="center">Beer Selection Page</h1>
    <form method="POST" action="selectBeer.do">
    Select Beer Characteristics<p>
    Color:
    <select name="color" size="1">
    <option value="light"> light </option>
    <option value="amber"> amber</option>
    <option value="brown"> brown </option>
    <option value="dark"> dark </option>
    </select>
    <br><br>
    <center>
    <input type="SUBMIT">
    </center>
    </form>
    </body>
    </html>


    Source to servlet BeerSelect.java


    package com.example.web;

    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;

    public class BeerSelect extends HttpServlet

    {
    public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
    {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("Beer Selection Advice<br>");
    String c = request.getParameter("color");
    out.println("<br>Got beer color " + c);

    }
    }



    Any ideas?
    Kurt, Jul 20, 2008
    #1
    1. Advertising

  2. Kurt

    Lew Guest

    On Jul 20, 1:28 pm, Kurt <> wrote:
    > Greetings;
    >
    > Specifics:
    >
    > OS: Win XP PRO
    > App Serv: Tomcat 5.5
    > Netbeans: 6.1
    >
    > Issue:  I am trying to port a simple single servlet from the first
    > example in Head First Servlets and JSP 2nd Edition to Netbeans 6.1.
    >
    > This example works fine when I deploy it manually under Tomcat.
    > However, I am getting a 404 error looking for /Beer-v1/selectBeer.do
    > when I try to run the version built and deployed with Netbeans.


    By what steps exactly are you telling NetBeans to deploy this app to
    the server, as opposed to simply building the app into the build/ and
    dist/ subdirectories?

    Are you running the Web app using NetBeans' "run" command, else how?

    --
    Lew
    Two questions, which you have not answered unless you provided two
    answers.
    Lew, Jul 21, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. circuit_breaker
    Replies:
    2
    Views:
    1,965
    Jack Jia
    Apr 4, 2004
  2. Pimousse
    Replies:
    2
    Views:
    3,607
    Roedy Green
    Apr 21, 2004
  3. Ilias Lazaridis
    Replies:
    0
    Views:
    886
    Ilias Lazaridis
    Dec 12, 2004
  4. Thomas G. Marshall
    Replies:
    2
    Views:
    809
    Thomas G. Marshall
    Oct 16, 2006
  5. Rakesh
    Replies:
    7
    Views:
    1,814
    David Segall
    Jul 3, 2008
Loading...

Share This Page