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