structs 中html:link 中 傳參的做法 作用是創建超鏈接

CreateMessageLink.jsp 中的代碼: 

   <% for(int i=0;i<l.size();i++){      
         Message messag=(Message)l.get(i);   //這是從數據庫中得到的(用的是hibernate)
        Integer idmess= messag.getIdmessage();  
        request.setAttribute("idm",idmess);
     %>   
    <html:link page="/messageLink.do" paramId="id" paramName="idm"><%=messag.getTitle() %></html:link><br/>

<%} %>

 

struts-config.xml中的配置:

<action
      attribute="messageLinkForm"
      input="/form/messageLink.jsp"
      name="messageLinkForm"
      path="/messageLink"
      scope="request"
      type="com.yourcompany.struts.action.MessageLinkAction" />

 

MessageLinkAction中的代碼:

     String id=request.getParameter("id");
     Integer idmessage=Integer.parseInt(id);
     request.getSession().setAttribute("idmessage", idmessage);
     return new ActionForward("/form/message.jsp");

 

在message.jsp中得到 idmessage

Integer idmessage=(Integer)request.getSession().getAttribute("idmessage");

....//下面可以用這個參數,得到數據庫的信息....等其它操作...

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章