直接在三个页面的开头调用此servlet的相关检查方法

解决方案 »

  1.   

    这个好办啊,请求的地址/**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
    this.doPost(request, response);
    } /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
    String resPath = request.getParameter("resPath");
    if("a".equals(resPath)){
    request.getRequestDispatcher("/a.jsp").forward(request, response);
    }else if("b".equals(resPath)){
    request.getRequestDispatcher("/b.jsp").forward(request, response);
    }else if("c".equals(resPath)){
    request.getRequestDispatcher("/c.jsp").forward(request, response);
    }
    }
      

  2.   

    这样能行吗?
    String resPath = request.getParameter("resPath");
    这句话是获取表单用的吧,能用来获取请求的地址?
      

  3.   

    配置filter过滤器
    <filter>
        <filter-name> servlet</filter-name>
        <filter-class>servlet全路径 </filter-class>  
     </filter>
      
    filter-mapping>  
        <filter-name>servlet</filter-name>  
        <url-pattern>*.jsp</url-pattern>  
    </filter-mapping> 
      

  4.   

    这样能行吗?
    String resPath = request.getParameter("resPath");
    这句话是获取表单用的吧,能用来获取请求的地址?
    不一定要表单的,直接在URL后面加参数也可以的,像这样:/loginServlet?param=a
      

  5.   

    把它变成一个转发servlet就行啦
    这个是在几乎所有框架中通用的做法dispatch servlet
      

  6.   

    用拦截器好了 。 action 下面配置好你的拦截类。 拦截类里面判断。
      

  7.   

      每次 只是改变URL的的路径不就完了,楼主看四楼
      

  8.   

    楼主应该配置一个登录filter做像下面这样的判断String username = request.getParameter("username");
    String password = request.getParameter("password");
    Map<String, String> messages = new HashMap<String, String>();if (username == null || username.isEmpty()) {
        messages.put("username", "Please enter username");
    }if (password == null || password.isEmpty()) {
        messages.put("password", "Please enter password");
    }if (messages.isEmpty()) {
        User user = userService.find(username, password);    if (user != null) {
            request.getSession().setAttribute("user", user);
            response.sendRedirect(request.getContextPath() + "/home");
            return;
        } else {
            messages.put("login", "Unknown login, please try again");
        }  
    }request.setAttribute("messages", messages);
    request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response);
      

  9.   

    这样能行吗?
    String resPath = request.getParameter("resPath");
    这句话是获取表单用的吧,能用来获取请求的地址?如果你是通过URL的方式,自然可以啊, action="*.do?resPath=a"