Problem with the deployment of servlet (Con't)

J

james

Refering to my previous post about my problem, I am using the Tomcat 5.0
which can easily deploy application by logging as the administrator.
Also, the URL can return the /servlet/ sometime and sometime directly jump
to internet optimizer page. Below are my file concerned.:
Some of you mentioned that it 's the problem of the invoker, can anyone tell
me more?? THousands Thanks

greeting/WEB-INF/web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc. //DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

<web-app>
<servlet>
<!-- Servlet alias -->
<servlet-name>GreetingServlet</servlet-name>

<!-- Fully qualified Servlet class -->
<servlet-class>GreetingServlet</servlet-class>
</servlet>
</web-app>



/greeting/index.html
<html>
<head>
<title>ProJava Registration111</title>
</head>
<body>
<h1>welcome</h1>
<form action="/greeting/servlet/GreetingServlet" method="POST">
<p>Your Name <input type="text" size="40" name="name"></p>
<p>Your Email <input type="text" size="40" name="email">
<input type = "submit" value="submit"></p>
</form>
</body>
</html>

greeting/WEB-INF/classes/servlet.class
greeting/WEB-INF/classes/servlet.java
import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.util.*;

public class GreetingServlet extends HttpServlet{
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException{
String name = request.getParameter("name");
String email = request.getParameter("email");

String message = null;
GregorianCalendar calendar = new GregorianCalendar();
if(calendar.get(Calendar.AM_PM) == Calendar.AM){
message = "Good Morning";
}
else{
message = "Good Afternoon";
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<body>");
out.println("<p>" + message + ", " + name + "</p>");
out.println("<p> Thanks for registering your email (" + email +
") with us.</p>");
out.println("<p> - The Pro Java Team. </p>");
out.println("</body>");
out.println("</html>");
out.close();
}
}

I am newbie to servlet and I am trying some simple example of servlet in
which I have written
1) a html form to get data saved in webapps/myplace/
2) a servlet which is to return the data got from the request.get of the
html form.
I have deployed the tomcat server, put the compiled servlet class in the
WEB-INF/classes and also make the web.xml file.
However, when I load the page to the servlet from the html form, and click
submit from the form which is supposed to link to the servlet, it returns
404 error which said it cannot load the page.
I would like to know what I have missed that lead to such problem.
Thousands Thanks
 
W

William Brogden

james said:
Refering to my previous post about my problem, I am using the Tomcat 5.0
which can easily deploy application by logging as the administrator.
Also, the URL can return the /servlet/ sometime and sometime directly jump
to internet optimizer page. Below are my file concerned.:
Some of you mentioned that it 's the problem of the invoker, can anyone tell
me more?? THousands Thanks

greeting/WEB-INF/web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc. //DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

<web-app>
<servlet>
<!-- Servlet alias -->
<servlet-name>GreetingServlet</servlet-name>

<!-- Fully qualified Servlet class -->
<servlet-class>GreetingServlet</servlet-class>
</servlet>
</web-app>

Aside from all other advice - put every class that has anything to do with a
servlet in a package.
It avoids all sorts of odd results and bugs. Naturally your servlet-class
tag and dirctory under
classes must then reflect the package.

A Yahoo search for "java invoker servlet" discovered a nice discussion at
JavaRanch
 
H

hiwa

You haven't given answers to our previous quesitions:

--previous post of mine---------------------------------------
We may need to know:
(1)The location you've stored the html and the servlet class,
relative to the Tomcat install dir.
(2)The value of FORM ACTION attribute and URL for the servlet
you used.
(3)Your web.xml.
(4)Your TOMCAT/conf/web.xml
....Some of the recent versions of Tomcat has disabled invoker servlet
in its conf/web.xml by default ... That might be the cause of your
problem.
------------------------------------------
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top