html、jsp中很多地方不能用绝对路径;
像<IMG src="/img/login_logo.gif">
request.sendRedirect(/jsp/login.jsp);
等等
-----------------------------------------
即:
要转到/jsp/login.jsp如果是来源是/image.jsp
我就要request.sendRedirect(./jsp/login.jsp);如果是来源是/a/image.jsp
我就要request.sendRedirect(./../jsp/login.jsp);如果是来源是a/b/image.jsp
我就要request.sendRedirect(./../../jsp/login.jsp);请指教?

解决方案 »

  1.   

    request.getContextPath()获得路径,然后拼上就行了,下面是解说getContextPath
    public java.lang.String getContextPath()Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.
    Returns:
    a String specifying the portion of the request URI that indicates the context of the request
      

  2.   

    如果是来源是/image.jsp
    我就要request.sendRedirect(./jsp/login.jsp);如果是来源是/a/image.jsp
    我就要request.sendRedirect(./../jsp/login.jsp);如果是来源是a/b/image.jsp
    我就要request.sendRedirect(./../../jsp/login.jsp);
    是对的