1、目录结构
10余年的巨鹿网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都营销网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整巨鹿建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“巨鹿网站设计”,“巨鹿网站推广”以来,每个客户项目都认真落实执行。
2、各文件内容
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>$Title$
web.xml
<?xml version="1.0" encoding="UTF-8"?>Servlet web.servlet.Servlet Servlet /Servlet
Servlet.java
package web.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet(name = "Servlet") public class Servlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("doPost()..."); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("doGet()..."); } }
正常运行后运行后,Server控制台会出现输出“doPost()...”字符
3、当未配置web.xml时,出现的错误提示
<?xml version="1.0" encoding="UTF-8"?>
解决方法:在web.xml中配置相关信息,或在Servlet.java注解中添加内容:
@WebServlet(name = "Servlet",urlPatterns = "/Servlet")
4、配置web.xml文件但未覆写doGet()和doPost()方法,或未覆写相对应的方法出现的错误提示
package web.servlet; @WebServlet(name = "Servlet") public class Servlet extends HttpServlet { }
package web.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet(name = "Servlet") public class Servlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("doGet()..."); } }
以上这篇基于创建Web项目运行时出错的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持创新互联。