天天看點

servlet通路路徑測試(path)

1、getContextPath:站點名[/context](Web應用的入口點名字)

2、getServletPath:servlet類的對應映射路徑[/resource]

3、getRequestURI:uri位址 = [/context] + [/resource]

4、getRequestURL:protocol://IP adderss:[port][/context][/resource][/?query string]

5、代碼顯例如下:

package com.tiger.path.action;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
/**
 * 結論:在jsp的标簽中寫入下面一段代碼,之後所有連結都可以使用絕對路勁,像這樣
 * ContextPath = ").append(request.getContextPath()).append("
").
    append("   ServeltPath = ").append(request.getServletPath()).append("
").
    append("   RquestURI = ").append(request.getRequestURI()).append("
").
    append("   RquestURL = ").append(request.getRequestURL()).append("
").
    append("   Scheme = ").append(request.getScheme()).append("
").
    append("   ServerName = ").append(request.getServerName()).append("
").
    append("   ServerPort = ").append(String.valueOf(request.getServerPort())+"");
  }
}