MyDispatcherServlet package prj.servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.*;public class MyDispatcherServlet extends HttpServlet { private static final long serialVersionUID = 1L; pri
package prj.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.*; public class MyDispatcherServlet extends HttpServlet { private static final long serialVersionUID = 1L; private static final String path = "/views/index.jsp"; public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String _uri = req.getRequestURI().substring(req.getContextPath().length()); if (_uri != null) { super.getServletContext().getRequestDispatcher(_uri.equals("/") ? path : path.replaceAll("index", _uri.replaceAll("^/|;.*", "").replaceAll("/$", "")) ).forward(req, resp); return; } resp.getWriter().print("fail!"); } }