Okay, I am a new learner and I am using as my first guide book. When I code like the book's example, I got in trouble with the beginning.
Here is the Java code:
import javax.servlet.http.*;
import java.io.*;
public class Ch1Servlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html>" +
"<body>" +
"<h1 align=center>HF\'s Chapter1 Servlet</h1>"
+ "<br>" + today + "</body>" + "</html>");
}
}
Here is the web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/
web-app_2_4.xsd"
version="2.4">
<Servlet>
<Servlet-name>Chapter1 Servlet</Servlet-name>
<Servlet-class>Ch1Servlet</Servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-name>Chapter1 Servlet</Servlet-name>
<url-pattern>/Serv1</url-pattern>
</Servlet-mapping>
</web-app>
This book let me "javac" the 'Ch1Servlet.java' to 'Ch1Servlet.class'. Then it teached me to create document in the 'tomcat'. Here is the path.
apache-tomcat-8.0.33\webapps\ch1\WEB_INF\classes
It lets me put 'web.xml' in the 'WEB_INF' document and put 'Ch1Servlet.class' in the 'classes' document. Then start the tomcat, I can visit "http:127.0.0.1:8080" in the browser but I cannot visit "http://localhost:8080/ch1/Serv1".
I use apache 8.0.33 and I do not know what can I do with it. The book is success in the example but I failed.
My English is very poor and I am a foreigner. I know many advanced people here and could you help me? I cannot solve the problem.