这是我的 Helloworld 课程
package java4s;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Helloworlsclass
*/
@WebServlet("/Helloworlsclass")
public class Helloworlsclass extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Helloworlsclass() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter printWriter = response.getWriter();
printWriter.println("<h1>Hello World!</h1>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
这是网络 XML 文件。
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>
HelloWorld
</servlet-name>
<sevlet-class>
/Helloworlsclass
</sevlet-class>
<servlet-mapping>
HelloWorld
</servlet-mapping>
<url-pattern>
/Helloworlsclass
</url-pattern>
</servlet>
</web-app>
我正在尝试使用此示例运行但浏览器不打印任何内容请告诉我在哪里做错了如何在 servlet 示例中打印 hello world