前提:正确安装JDK和Resin3.0
这个是原始文档,我做一下注释
Configuring the web.xml
The following is a complete working web.xml to run this example.
The tells Resin that the URL should invoke the servlet.
The tells Resin that uses the class and that the value of the init parameter is .
<web-app> <servlet-mapping url-pattern='/hello' servlet-name='hello-world'/> <servlet servlet-name='hello-world' servlet-class='test.HelloWorld'> <init-param greeting='Hello, World'/> </web-app> |
<web-app> <servlet servlet-name='hello-world' servlet-class='test.HelloWorld'/> |
原始文档中有三个错误,我也不知道是不是我错了!但是我改过三个错误,运行成功!
1。servlet servlet-name标签应该放在servlet-mapping前面。
2。<servlet servlet-name='hello-world' servlet-class='test.HelloWorld'>标签结尾少了一个" / "。
3。<init-param greeting='Hello, World'/> 这句标签我去掉了,不然也无法运行!
The Java code, belongs in
$app-dir/WEB-INF/classes/test/HelloWorld.java |
Or, if you're compiling the servlet yourself, the class file belongs in
$app-dir/WEB-INF/classes/test/HelloWorld.class |
Following is the actual servlet code. It just prints a trivial HTML page filled with the greeting specified in the web.xml.
and are included mostly for illustration. Resin will call when it starts the servlet and before Resin destroys it.
package test; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { private String greeting; public void init() throws ServletException { greeting = getInitParameter("greeting"); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("<title>" + greeting + "</title>"); out.println("<h1>" + greeting + "</h1>"); } public void destroy() { // nothing to do } } |
它文档中的这个用了那个<init-param greeting='Hello, World'/>标签,由于我删除了,所以无法使用!
就用着吧!保存为HelloWorld.java放在WEB-INF/classes/test目录下面。
package test; public class HelloWorld extends HttpServlet{ |
开启Resin服务,在浏览器中输入 http://localhost:8080/hello
即可以正确访问!