我使用Servlet接口创建了一个Servlet程序,我只是使用响应接口方法getWriter()将我的响应发送到浏览器,它返回PrintWriter引用,我试图在浏览器上打印以下信息,如Hello和Date
但是,我收到了以下404错误。
任何人都可以指导我为什么?
我的Servlet程序代码。
class FirstAppUsingServlet implements Servlet
{
public void init(ServletConfig config) throws ServletException
{
}
public void destroy()
{
}
public ServletConfig getServletConfig()
{
return null;
}
public String getServletInfo()
{
return null;
}
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
{
Date d1=new Date();
System.out.println(d1);
PrintWriter out=response.getWriter();
out.println("Hello Java");
out.println(d1);
}
}
web.xml的代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>FirstServletApp</display-name>
<servlet>
<description></description>
<display-name>FirstAppUsingServlet</display-name>
<servlet-name>FirstAppUsingServlet</servlet-name>
<servlet-class>FirstAppUsingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstAppUsingServlet</servlet-name>
<url-pattern>/FirstAppUsingServlet</url-pattern>
</servlet-mapping>
</web-app>
以下错误:
http://localhost:8089/FirstServletApp/WEB-INF/classes/FirstAppUsingServlet.java
答案 0 :(得分:-1)
做几件事:
首先检查TOMCAT服务器是否正常启动。为此,请检查 来自浏览器的http://localhost:8080/。我在假装你已经启动了8080端口的服务器。 如果Server正确启动,那么您将看到TOMCAT主页。如果不是,则必须检查JAVA_HOME环境变量设置。
检查编辑器控制台页面是否有任何错误。
检查您的网址是否正确,因为您尚未在此处粘贴网址。