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