servlet的xml配置

构建过程

项目结构如图


image.png

pom.xml依赖,导入servlet包



    4.0.0

    com.haijunyin
    servletdemo-xmlconfig
    1.0-SNAPSHOT

    war

    
        
            javax.servlet
            javax.servlet-api
            3.1.0
        
    


HelloServlet.java继承HttpServlet

package com.haijunyin.servletdemo.xmlconfig.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HelloServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("HelloServlet...doGet...");
        resp.getWriter().write("hello...");
    }
}

web.xml配置映射



    web02
    
        index.html
        index.htm
        index.jsp
        default.html
        default.htm
        default.jsp
    
    
        
        HelloServlet
        
        com.haijunyin.servletdemo.xmlconfig.servlet.HelloServlet
        
    
    
        
        HelloServlet
        
        /hello
        
    

index.jsp请求页

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>


    
    
        hello
    

运行结果

把应用加入tomcat启动


image.png

你可能感兴趣的:(servlet的xml配置)