举例来说明一下
比如要写一个简单的hellservlet:
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
@WebServlet(name = "hello",urlPatterns = {"/hello.do"})
public class HelloServlet extends javax.servlet.http.HttpServlet {
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
doGet(request,response);
}
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
response.getWriter().print("hello");
}
}
这时候配置tomcat我们会发现
如图,URL配置不再只是localhost:8080/就结束了,所以访问的时候,如果只输入“http://localhost:8080/hello.do”就会报出404找不到网页的错误,而是需要输入"http://localhost:8080/SpringBootReview_war_exploded/hello.do"才能找到对应的网页。
因为自己遇到了这种问题就赶紧记录一下,希望能有用~~