Porting single servlet example to NetBeans 6.1 - Java
This is a discussion on Porting single servlet example to NetBeans 6.1 - Java ; 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 ...
-
Porting single servlet example to NetBeans 6.1
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?
-
Re: Porting single servlet example to NetBeans 6.1
On Jul 20, 1:28 pm, Kurt <kharl...@qwest.net> 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.