問題:
我要在同一個portlet里面實現(xiàn)頁面的跳轉(zhuǎn),并傳遞參數(shù),該怎么做呢
比如說jsp文件為A.jsp和B.jsp,java文件為portlet.java,
我在A.jsp里面這樣寫:
PortletURI url=portletResponse.createURI();
url.addPatameter("index ", " "+index);(index為int型,即我要傳遞的參數(shù))
<a href="<%=url%>">Go to B.jsp當(dāng)我點擊此鏈接后,portlet.java中的doview()被調(diào)用,而我怎樣在doView()中獲取這個index參數(shù)呢,然后做一些處理,轉(zhuǎn)到B.jsp頁面呢.
答:
portlet分響應(yīng)動作和呈現(xiàn)兩個階段,最好不要在doview里處理邏輯。你可以<a href="<portletAPI:createURI><portletAPI:URIAction name='<%=actionString%>'/><portletAPI:URIParameter name= "index " value= "1 "/> </portletAPI:createURI> "> go to b.jsp </a> ,在portlet的actionPerformed函數(shù)里相應(yīng)該請求,而doView()決定include哪個jsp。另外如果是彈出,可以用 <a href= " <%=response.encodeURL( "/jsp/html/b.jsp?index=1 ")%> " target= "_blank "> open b.jsp </a> 。
其中actionString是你自己定義的動作名稱,例如 "com.directAction ",而第二種方式好像也可以直接轉(zhuǎn)到b頁面(去掉target,不過不推薦這樣做),
public void actionPerformed(ActionEvent event) throws PortletException{
String actionString = event.getActionString();
PortletRequest request = event.getRequest();
if(actionString.equals(someaciton)){
//do something
}
}