Java Web_实现Servlet多重映射

 (1)新建Servlet

package hello;

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

/**
 * 
 * @author 新林
 * @Date 2019年9月27日
 */

public class helloServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public helloServlet() {
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}

(2)配置多重映射 



  Hello
  
    index.html
    index.htm
    index.jsp
    default.html
    default.htm
    default.jsp
  
  
  	helloServlet
  	hello.helloServlet
  
  
  
  	helloServlet
  	/helloServlet
  
  
  
  	helloServlet
  	/Test
  
  
  
  	helloServlet
  	/
  
   
  
  	helloServlet
  	/a*
  
  

(3)启动tomcat 

       访问链接:localhost:8080/Hello/helloServlet

       缺省访问:localhost:8080/Hello/

       通配符访问:localhost:8080/Hello/123(任意字符 如:123)

你可能感兴趣的:(Java,Web)