1、目录结构

2、各文件内容

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<form action="/Servlet" method="post">
<input type="submit" value="提交">
</form>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>Servlet</servlet-name>
<servlet-class>web.servlet.Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/Servlet</url-pattern>
</servlet-mapping>
</web-app>

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-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>

解决方法:在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项目运行时出小错误及解决方法的更多相关文章

  1. Apache commons StringUtils 在运行时出现NoClassDefError错误的解决方法

    Apache commons StringUtils 在运行时出现NoClassDefError错误的解决方法 在用tomcat运行WEB项目,并且使用了StringUtils包的时候,会出现 jav ...

  2. 启动web项目,报内存不足错误的解决方法

    Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: Java heap space 原因: 在 ...

  3. 在web项目启动时,使用监听器来执行某个方法

    在web项目中有很多时候需要在项目启动时就执行一些方法,而且只需要执行一次,比如:加载解析自定义的配置文件.初始化数据库信息等等,在项目启动时就直接执行一些方法,可以减少很多繁琐的操作. 这里写了个简 ...

  4. windows server,nginx安装,配置,运行nodeJS后端的web项目的实现,以及错误分析及解决方法

    一.安装nginx 下载windows版nginx (http://nginx.org/download/nginx-1.12.2.zip),之后解压到需要放置的位置(C:\nginx) 二.将Ngi ...

  5. Maven命令行创建web项目,并部署到jobss当中(解决No plugin found for prefix 'jboss-as' in the current project and in the plugin groups [org.apache.maven.plugins,问题)

    首件创建项目:此处可参照:http://maven.apache.org/guides/mini/guide-webapp.html mvn archetype:generate -DgroupId= ...

  6. VS2015 新Web项目(C#6)出现CS1617错误的解决

    VS2015新增了对C#6的支持. 在新的Web项目模板中通过引入nuget包Microsoft.CodeDom.Providers.DotNetCompilerPlatform:1.0.0并在web ...

  7. 执行游戏时出现0xc000007b错误的解决方法

    如图,这个错误使无数玩家烦恼. 出现这个错误,可能是硬件的问题,也可能是软件的问题.可是,因为硬件引起该问题的概率非常小,而且除了更换硬件之外没有更好的解决方法,因此本文将具体介绍怎样通过软件解决此问 ...

  8. gcc编译通过,运行却显示“段错误”的解决方法

    ​第一次在Liunx上(liunx mint 17)使用gcc编译c文件,竟然提示“找不到stdio.h",经过google后发现执行 sudo apt-get install build- ...

  9. jetty java文件无法删除 java文件占用 delete无效 运行时锁定静态资源的解决方法

    前几天jetty下发现java无法删除文件,文件操作后一直被jvm占用,无奈换了tomcat问题消失. 今天又想起来,尝试网上的解决方法,经本人试验,直接修改配置文件有时不能生效,具体原因不清楚,建议 ...

随机推荐

  1. 如何无人值守安装linux系统(上)

    如何开始 Linux 的无人值守安装 一.预备知识: I.什么是PXE PXE并不是一种安装方式,而是一种引导方式.进行PXE安装的必要条件是要安装的计算机中包含一个PXE支持的网卡(NIC),即网卡 ...

  2. 总结day12 ----装饰器

    一,什么是装饰器? 装饰器本质上就是一个python函数,他可以让其他函数在不需要做任何代码变动的前提下,增加额外的功能,装饰器的返回值也是一个函数对象. 装饰器的应用场景:比如插入日志,性能测试,事 ...

  3. leetcode-867-Transpose Matrix(矩阵由按行存储变成按列存储)

    题目描述: Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped o ...

  4. QuantLib 金融计算——基本组件之 Index 类

    目录 QuantLib 金融计算--基本组件之 Index 类 QuantLib 金融计算--基本组件之 Index 类 Index 类用于表示已知的指数或者收益率,例如 Libor 或 Shibor ...

  5. QuantLib 金融计算——数学工具之求解器

    目录 QuantLib 金融计算--数学工具之求解器 概述 调用方式 非 Newton 算法(不需要导数) Newton 算法(需要导数) 如果未做特别说明,文中的程序都是 Python3 代码. Q ...

  6. L05-Linux部署msmtp+mutt发送邮件

    一.前言 首先,得明白发送一封邮件的流程,下面一段理论摘抄自廖雪峰的官网网站https://www.liaoxuefeng.com/article/00137387674890099a71c04005 ...

  7. Django环境搭建之hello world

    当我们想用Python来开发一个web应用时,首先要选择一个优秀的web框架,Django是个非常成熟的web开发框架,网上具有丰富的文档和学习资料,所以选择Django框架来入门web开发是个不错的 ...

  8. P3440 [POI2006]SZK-Schools

    传送门 应该是很显然的费用流模型吧... $S$ 向所有学校连边,流量为 $1$,费用为 $0$(表示每个学校要选一个编号) 学校向范围内的数字连边,流量为 $1$,费用为 $c|m-m'|$(表示学 ...

  9. Access network

    1       State transfering A•Mobility:开机-搜寻PLMN/CELL来发现自己在网络中的位置•Attach request•Auth request•Auth res ...

  10. springcloud(七)-Feign声明式REST调用

    前言 前面我们使用的RestTemplate实现REST API调用,代码大致如下: public User findById(@PathVariable Long id) { return rest ...