[Original] Use the tags in Struts

xiaoxiao2021-03-06  68

Use the tag in Struts to complete some complex loops. Here is a small example of this:

IterateBean.java:

Package beantest;

Import org.apache.struts.Action.actionform;

public class IterateBean extends ActionForm {private String [] name_coll = null; public void setName_coll (String [] name_coll) {this.name_coll = name_coll;} public String [] getName_coll () {return this.name_coll;} private String [] name_new = null; public void setName_new (String [] name_new) {System.out.println ( "IterateBean: setName_new (String [])"); this.name_new = name_new;} public String [] getName_new () {return this.name_new }}

IteeAction.java

Package beantest;

Import javax.servlet.http.httpservletRequest; import javax.servlet.http.httpservletResponse;

Import org.Apache.struts.Action.Act; import org.apache.struts.action.actionform; import org.apache.struts.action.actionforward; import org.apache.struts.Action.Apache.APPING;

public class IterateAction extends Action {public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {IterateBean ibean = (IterateBean) form; String [] temp = { "bitan", "helen"}; ibean. SetName_coll (Temp); Temp = new string [] {"aaaaa", "bbbb"}; ibean.setname_new (temp); return maping.findforward ("Iterate-View");}}

Iterate-view.jsp:

<% @ Page ContentType = "text / html; charset = GB2312"%>

<% @ Taglib Uri = "/ Web-inf / struts-logic.tld" prefix = "logic"%> <% @ Taglib URI = "/ Web-inf / struts-bean.tld" prefix = "bean"%> Name: <% = iteerate%> ; code: <% = itereate_new%>

★ 〓〓〓〓〓〓〓 ★

Lower.jsp:

Hello, Iterate!

Struts-config.xml:

< Action-mapings> web.xml:

action org.apache.struts.Action.ActionServlet config /web-inf/struts-config.xml 1 < servlet-maping> action / eye / *

Output effect:

Name: Bitan; Code: Aaaaaname: Bitan; Code: bbbbb ★ 〓〓〓〓〓〓〓 ★ Hello, Ite: Aaaaaname: Helen; Code: bbbbb ★ 〓〓〓〓〓〓〓 ★ ★ 〓〓;; Hello, Iteerate!

As shown above, multiple variables cannot be simultaneously output directly in a cycle; but nesting cycles in the loop can achieve a complex effect.

To achieve multiple variables simultaneously in a loop, you can reference , tag.

转载请注明原文地址:https://www.9cbs.com/read-120013.html

New Post(0)