标签:学习 package ice info request pat 方式 vat class
------------------------------------------------------------------------------
准备工作:1、创建一个web 项目
2、创建一个Servelt (这里采用注解开发)(Servlet开发方式 xml 注解 Java )
3、创建一个jsp
________________________________
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; /** * 不过滤jsp * * * font 设计模式,前端设计模式 * @author Allen17805272076 * */ @WebServlet("/") public class DispatchServlet extends HttpServlet{ /** * */ private static final long serialVersionUID = 8819789068715278298L; @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub String string = req.getParameter("control"); System.out.println(string); if(string.equals("demo1")) { System.out.println("demol被调用"); } if(string.equals("demo2")) { System.out.println("demo2被调用"); } if(string.equals("demo3")) { System.out.println("demo3被调用"); } if(string.equals("demo4")) { System.out.println("demo4被调用"); } System.out.println("执行控制器"); } }
-------------------------------------------------------------------------------------------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="dispatcher?control=demo1">跳转1</a>
<a href="dispatcher?control=demo2">跳转2</a>
<a href="dispatcher?control=demo3">跳转3</a>
<a href="dispatcher?control=demo4">跳转4</a>
</body>
</html>
标签:学习 package ice info request pat 方式 vat class
原文地址:https://www.cnblogs.com/zwyzwy/p/11731535.html