我面臨在Struts2一個奇怪的錯誤,我正在試圖設置屬性轉換請求範圍時,零指示字例外,Struts2的獲取請求對象爲空
Struts Problem Report
Struts的已檢測到一個未處理 異常:消息:文件: 組織/阿帕奇/卡塔利娜/連接器/ Request.java 行號:1,424
Stacktraces
java.lang.NullPointerException
org.apache.catalina.connector.Request.setAttribute(Request.java:1424)
org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:503)
javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:284)
com.inrev.bm.action.IRBrandMgmtAction.wrdTwts(IRBrandMgmtAction.java:81)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
我下面的代碼中給出,
public class IRBrandMgmtAction extends ActionSupport implements SessionAware,ServletRequestAware {
private static final long serialVersionUID = 1L;
private Map session;
private HttpServletRequest request;
private IRWordToTrack wrdtotrack;
private IRBrandMgmtDAO brandMgmtDAO;
private static org.apache.log4j.Logger log = Logger.getLogger(IRBrandMgmtAction.class);
,並在那裏發生這種情況的方法,
public String wrdTwts()
{
ArrayList<IRBrandTrackBean> messages = null;
IRDateUtil dtUtil = new IRDateUtil();
String wordId = request.getParameter("wordId");
IRUser user = (IRUser) session.get("user");
IRWordToTrack word = brandMgmtDAO.getWord(Integer.parseInt(wordId));
if(word!=null)
{
messages = brandMgmtDAO.viewMsgForUser(word.getWord().toUpperCase().trim(), null, dtUtil.getTimeZoneOffset(user.getTimeZone()));
}
request.setAttribute("messages",messages);
return "tweets";
}
我使用Tomcat 6服務器。
問候, 羅希特
感謝Leonbloy, 對於struts2來說,我真的很新,一直在使用struts1.2直到這個項目,感謝您的所有建議。只有幾個問題想, *你會建議什麼是在strust2中傳遞值的最好方法,定義getter setter? *當我使用這個HttpServletRequest request = ServletActionContext.getRequest()時,請求對象null的錯誤似乎不會發生。 你能拋出一些光嗎? – sesmic 2010-08-28 17:54:21