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