【发布时间】:2017-04-25 17:42:32
【问题描述】:
我正在使用 Java 和 Servlet 制作一个简单的 Web 应用程序,但我似乎无法访问地址:http://localhost:8080/Financeiro/oi-mundo,应该可用。
这是我的 Servlet:
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 OiMundoServlet
*/
@WebServlet("/oi-mundo")
public class OiMundoServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
System.out.println("Ola mamae");
out.print("<html>");
out.print("<body><h1>Oi Mundo</h1></body>");
out.print("</html>");
out.flush();
}
}
这里是 pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.algaworks</groupId>
<artifactId>Financeiro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
项目和控制台都没有错误,只有警告:[SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Financeiro' did not find a matching property.
尝试访问地址时,控制台中也没有出现任何消息,但我不确定它应该。
【问题讨论】:
标签: java servlets servlet-3.0