2011-04-21 105 views
0

我怎麼能動態輪廓號碼映射到一個servlet例如如何將動態配置文件編號映射到servlet?

http://stackoverflow.com/questions/2585407 

我想這個2585407映射到一個servlet這可能嗎?

感謝

+0

相關:http://stackoverflow.com/questions/2913351/jsp-servlets-simple-question/2913396#2913396 – BalusC 2011-04-21 14:13:06

回答

1

是的,可以有多種選擇:

  • 使用UrlRewriteFilter給定的URL改寫爲questions?id=2585407,然後閱讀請求參數
  • 使用像Spring-MVC這樣的框架支持美麗的URL
  • 該servlet映射到/questions/*(在web.xml中),然後解析getRequestURI()(通過剝離前綴和request.getContextPath())如果你的<url-mapping>設置爲

    /questions/* 
    

    ,那麼你會

1

使用以下的URL映射模式

/questions/* 
1

通過使用request.getPathInfo()(請求是HttpServletRequest)獲得您的問題ID。