一、作用
对于/web-INF/及其子目录,不允许直接的公共访问,所以就可以起到保护这些代码未经授权的访问和窥视,更好的保护了源代码。
写一个servlet,作为客户端的跳转。
二、代码
package com.cxhd.nurse.controller; 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; @WebServlet(name = "RouteSerlvet", urlPatterns = {"/route/*"}) public class RouteSerlvet extends HttpServlet{ protected void processRequest(HttpServletRequest request, HttpServletResponse response) { String url = request.getRequestURL().toString(); int p = url.indexOf("/route/"); String path = "/WEB-INF/page/"+url.substring(p+7)+"?"+request.getQueryString(); try { request.getRequestDispatcher(path).forward(request, response); } catch (ServletException | IOException e) { e.printStackTrace(); }; } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } }
三、url
对于WEB-INF下面的page/common/clerk/clerk_manage.jsp,可以输入http://localhost:8080/nurse/route/common/clerk/clerk_manage.jsp访问
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/class_horse/article/details/47323223