SORU
8 ŞUBAT 2011, Salı


'getRequestURİ arasındaki fark ne ve HttpServletRequest içinde getPathİnfo yöntemleri?

Basit, çok basit ön-kontrol yapıyorum. Doğru olanı seçmek için, farklı işleyicileri (eylemler) için istek yollar eşleşmesi gerekiyor.

Benim yerel makine HttpServletRequest.getPathInfo() HttpServletRequest.getRequestURI() getirisi aynı sonuçlar. Ama üretim ortamında ne cevap verecekler emin değilim.

Bu yöntem arasındaki fark nedir ve ben hangisini yapmalıyım?

CEVAP
10 Ocak 2014, Cuma


Küçük bir karşılaştırma tablosu burada (bir yere) koymak

Sunucu uygulaması /test?/* ve *uygulama 4* altında dağıtılmış olarak eşleştirilir.

http://30thh.loc:8480/app/test?/a? b;jsessionid=S? ID?p 1=c d&p 2=e f#a

Method              URL-Decoded Result           
-------------------------------------------------
getContextPath()                /app
getLocalAddr()                  127.0.0.1
getLocalName()                  30thh.loc
getLocalPort()                  8480
getMethod()                     GET
getPathInfo()           yes     /a? b
getProtocol()                   HTTP/1.1
getQueryString()        no      p 1=c d&p 2=e f
getRequestedSessionId() no      S? ID
getRequestURI()         no      /app/test?/a? b;jsessionid=S ID
getRequestURL()         no      http://30thh.loc:8480/app/test?/a? b;jsessionid=S ID
getScheme()                     http
getServerName()                 30thh.loc
getServerPort()                 8480
getServletPath()        yes     /test?
getParameterNames()     yes     [p 2, p 1]
getParameter("p 1")     yes     c d

Sunucu yukarıdaki örnek localhost:8480 çalışan ve 8* *adı hosts OS dosyasına kondu.

Yorum

  • "" boşluk olarak ele alınır sorgu dizesinde

  • "#Bir" sunucuya aktarılır. çapa Sadece tarayıcı ile çalışabilir.

  • Eğer url-pattern uygulamasında eşleme * (örneğin /test *.jsp), getPathInfo() döner null ile bitmiyor.

Eğer Spring MVC kullanılır

  • Yöntem getPathInfo() null döndürür.

  • Yöntem getServletPath() bağlam yolu ve oturum KİMLİĞİ arasında döndürür. Değeri yukarıdaki örnekte /test?/a? b olurdu

  • @RequestMapping Bahar @RequestParam URL kodlanmış parçaları ile dikkatli olun. (Geçerli sürüm 3.2.4) arabası ve genellikle not working as expected.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Jack Vale Films

    Jack Vale Fi

    8 ŞUBAT 2007
  • RFS Dan

    RFS Dan

    22 Temmuz 2014
  • VideoGamePervert

    VideoGamePer

    30 AĞUSTOS 2008