Help with j2ee beginner's question.

D

DaLoverhino

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
 
J

Juha Laiho

DaLoverhino 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
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

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,099
Latest member
AmbrosePri
Top