Servlet(サーブレット)リファレンス(逆引き)

Servlet(サーブレット)リファレンス
 
Web struts.wasureppoi.com
コンテキストパスを取得する:HttpServletRequest#getContextPath()
スポンサード リンク

コンテキストパスを取得するには、HttpServletRequest#getContextPath()を使用する。

HttpServletRequest#getContextPath()は、ServletContext#getContextPath()と同じ機能になります。

構文
javax.servlet.http.HttpServletRequest
 public String getContextPath( )
説明
getContextPathメソッドは、コンテキストパスを返します。
  
例1) コンテキストパスを取得する。

public class SampleServlet extends HttpServlet {

  public void doGet( HttpServletRequest request, HttpServletResponse response )
      throws ServletException,IOException {

    response.setContentType("text/html;charset=Windows-31J");

    PrintWriter out = response.getWriter();
    out.println("<html><body>");
    out.println("Context Path=" + request.getContextPath());
    out.println("</body></html>");
   }
}


リクエストURL

http://127.0.0.1:8080/ServletJsp/std/aaa/zzz?param01=001&param02=002


実行結果


スポンサード リンク


コンテキストパスを取得する:HttpServletRequest#getContextPath()
リクエストURLを取得する:HttpServletRequest#getRequestURL()
リクエストURIを取得する:HttpServletRequest#getRequestURI()
拡張パスを取得する:HttpServletRequest#getPathInfo()
クエリ情報(クエリーストリング)を取得する:HttpServletRequest#getQueryString()
サーブレットパスを取得する:HttpServletRequest#getServletPath()

Servletへ
忘れっぽいエンジニアのJakarta Strutsリファレンス TOPへ