<servlet> <servlet-name>ServletDemo</servlet-name> <servlet-class>www.hw.web.ServletDemo</servlet-class> </servlet> <servlet-mapping> <servlet-name>ServletDemo</servlet-name> <url-pattern>/servletDemo/*</url-pattern> </servlet-mapping>
public class ServletDemo extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // int money = 100; String path = req.getRequestURI(); path = path.substring(path.lastIndexOf("/")); if ("/vip".equals(path)) { System.out.println("vip九折" + money * 0.9); } else if ("/vvip".equals(path)) { System.out.println("vvip五折" + money * 0.59); } else { System.out.println("其它打骨折" + money * 100); } } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("post请求"); } }
标签:多路径,映射,money,System,ServletDemo,println,path,Servlet,out From: https://www.cnblogs.com/weiduaini/p/17240393.html