我是j2EE的新手,现在正在学习servlet。我使用servlet在网页中显示一个简单的 " Hello World" 字符串。 我的代码是:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<head><title>Hello World</title></title>");
pw.println("<body>");
pw.println("<h1>Hello World</h1>");
pw.println("</body></html>");
}
}
如何为 HelloWorld.html
提供此网页的名称答案 0 :(得分:-1)
它可以帮助你:
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>(with package name).HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>HelloWorld.html</url-pattern>
</servlet-mapping>