Hello.
I am trying to learn J2ee. I have a GuestBook program. It's an
index.html page that calls a servlet. The servlet just adds a message
to to HttpServletRequest. The servlet then calls a jsp to display the
message it set.
Here's my directory:
...\webapps\MyApps\GuestBook\index.html
...\webapps\MyApps\GuestBook\WEB-INF\web.xml
...\webapps\MyApps\GuestBook\WEB-INF\classes\web\GuestBookWrite.java
...\webapps\MyApps\GuestBook\WEB-INF\classes\web\GuestBookWrite.class
So the third entry in index.html "calls" GuestBookWrite.java which adds
a message to HttpServletRequest. It's this step which Apache complains
that GuestBookWrite is not available:
HTTP Status 404 - /MyApps/GuestBook/GuestBookWrite
I'm wondering if anyone can spot what I'm doing wrong here.
Here's the contents of index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Guest Book</title>
</head>
<body>
<h1>Guest Book</h1>
<p>
<a href="ReadGuestBook.html">See all GuestBook
entries.</a>
</p>
<p>
<a href="WriteGuestBook.html">Enter GuestBook
entry.</a>
</p>
<p>
<a href="GuestBookWrite">Enter GuestBook
entry using Servlet class.</a>
</p>
</body>
</html>
Here's web.xml:
<?xml version="1.0" encoding="1.0" ?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Guest Book Project</display-name>
<servlet>
<servlet-name>GuestBookWrite</servlet-name>
<servlet-class>web.GuestBookWrite</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GuestBookWrite</servlet-name>
<url-pattern>/GuestBookWrite</url-pattern>
</servlet-mapping>
</web-app>
Here's GuestBookWrite.java:
package web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class GuestBookWrite extends HttpServlet {
//public void init() //will use default.
public void doPost( HttpServletRequest request,
HttpServletResponse response) {
doGet( request, response);
}
public void doGet( HttpServletRequest request,
HttpServletResponse response) {
try {
String message;
RequestDispatcher dispatcher;
ServletContext context = getServletContext();
message = "GuestBookWrite: message added.";
request.setAttribute( "GuestMessage", message);
dispatcher = context.getNamedDispatcher( "DisplayGuests");
dispatcher.forward( request, response);
}
catch( Exception e) {
log( "Exception in GuestBookWrite: " + e.getMessage());
}
return;
} // doGet
} // GuestBookWrite
Juha Laiho - 25 Jun 2006 13:04 GMT
"DaLoverhino" <DaLoveRhino@hotmail.com> said:
>I am trying to learn J2ee. I have a GuestBook program. It's an
>index.html page that calls a servlet. The servlet just adds a message
[quoted text clipped - 6 lines]
>
>...\webapps\MyApps\GuestBook\WEB-INF\web.xml
It could be that your server sees the MyApps as the application, and as
there is no MyApps/WEB-INF/web.xml, just deploys the application with
some (server internal) defaults (which certainly doesn't include seeking
the directory space for "potential" servlet classes).
Everything else seems fine, but looks like you should drop the MyApps level
completely, and place the GuestBook directly on webapps level.

Signature
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)