JavaWeb——request獲取相關路徑

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        http://localhost:8080/DemoName/AServlet?username=xxx&password=yyy
        request.getScheme();//獲取協議,http
        request.getServerName();//獲取服務器名,localhost
        request.getServerPort();//獲取服務器端口,8080
        request.getContextPath();//獲取項目名,/DemoName
        request.getServletPath();//獲取Servlet路徑,/AServlet
        request.getQueryString();//獲取參數部分,即問號後面的部分,username=xxx&password=yyy
        request.getRequestURI();//獲取請求URI,即項目名+Servlet路徑,/DemoName/AServlet
        request.getRequestURL();//獲取請求URL,等於不包括參數的整個路徑,http://localhost:8080/DemoName/AServlet
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章