正在使用Spring MVC框架並使用view preparer來加載菜單。我需要在viewpreparer類中獲取請求對象。對於這是使用以下代碼在視圖preparer如何在viewpreparer類中獲取HttpServletRequest
@Service
public class MenuViewPreparer implements ViewPreparer {
HttpServletRequest request = ServletActionContext.getRequest();
// HttpSession session = request.getSession();
public void execute(TilesRequestContext tilesContext,
AttributeContext attributeContext) throws PreparerException {
// MenuList fetches the list of all the main menus by calling the getMenuList() method present in MenuServiceDAOImpl
// which is of type MenuDTO
String user=null;
System.out.println("Menu :"+request.hashCode());
UserDTO userDTO = UserName.getUserName(request);
user=userDTO.getUserId();
}
}
我需要執行方法中的請求對象。但所有我都在null中獲取請求對象。所以得到一個例外。誰能告訴我如何得到它?
在此先感謝。
http://stackoverflow.com/questions/15779374/apache-tiles-how-to-get-httpservlet-request-object-in-execute-method-of-viewprThis問題已經提出,但沒有答案,但。 – Akshar
但答案不起作用。 –