STRUTS1 Four: Common labels

Source: Internet
Author: User

5 Types of tags supported by struts1:
HTML Tags: used to create HTML input forms that interact with the struts framework and other appropriate HTML tags
Bean Tags: used when accessing JavaBeans and its properties, and defining a new bean
<%@ taglib uri= "Http://struts.apache.org/tags-bean" prefix= "Bean"%>
Logic Tags: manage the output generated by conditions and the loops generated by the set of objects
<%@ taglib uri= "http://struts.apache.org/tags-logic" prefix= "logic"%>
Template Label: As the tiles framework package appears, this tag has started to reduce the use of
Nested Tags: enhanced ability to nest use of other struts tags

Set properties in action and remove properties from JSP
Loginaction

 Packagecom.bjpowernode.struts;Importjava.util.ArrayList;Importjava.util.Date;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;Importorg.apache.struts.action.Action;ImportOrg.apache.struts.action.ActionForm;ImportOrg.apache.struts.action.ActionForward;Importorg.apache.struts.action.ActionMapping; Public classLoginactionextendsaction{@Override PublicActionforward Execute (actionmapping mapping, actionform form, httpservletrequest request, HTTPSERVLETRESPO NSE response)throwsException {loginactionform LAF=(loginactionform) Form; if("admin". Equals (Laf.getusername ()) && "Admin". Equals (Laf.getpassword ())) {Request.setattribute ("Message", "Test message!"); Request.setattribute ("User", CreateUser ("Zhang San", "123456", 29)); Request.setattribute ("UserList", Createuserlist ()); Request.setattribute ("UserMap", Createusermap ()); returnMapping.findforward ("Success"); }        returnMapping.findforward ("Error"); }    PrivateUser CreateUser (string Username, string password,intAge ) {User User=NewUser ();        User.setusername (username);        User.setpassword (password);        User.setage (age); User.setcreatedate (NewDate ()); returnuser; }        PrivateList<user>createuserlist () {List<User> userlist =NewArraylist<user>(); Userlist.add (CreateUser ("John Doe", "123123", 30)); Userlist.add (CreateUser ("Harry", "123999", 34)); Userlist.add (CreateUser ("Zhao Liu", "123123", 39)); returnuserlist; }        PrivateMap<string, user>Createusermap () {Map<string, user> map =NewHashmap<string, user>(); Map.put ("K1", CreateUser ("Map1", "map123", 100)); Map.put ("K2", CreateUser ("Map2", "map12123", 110)); Map.put ("K3", CreateUser ("Map3", "Map123map", 130)); returnmap; }}

Post-Jump JSP
login_success.jsp

<%@ Page Language="Java"Import="java.util.*"pageencoding="GB18030"%><%@ taglib URI="Http://struts.apache.org/tags-bean"prefix="Bean" %><%@ taglib URI="Http://struts.apache.org/tags-logic"prefix="Logic" %> <%StringPath=Request.getcontextpath ();StringBasePath=Request.getscheme ()+"://"+Request.getservername ()+":"+Request.getserverport ()+Path+"/";%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML>  <Head>    <Basehref= "<%=basePath%>">        <title>My JSP ' login_success.jsp ' starting page</title>        <Metahttp-equiv= "Pragma"content= "No-cache">    <Metahttp-equiv= "Cache-control"content= "No-cache">    <Metahttp-equiv= "Expires"content= "0">        <Metahttp-equiv= "keywords"content= "Keyword1,keyword2,keyword3">    <Metahttp-equiv= "description"content= "This is my page">    <!--<link rel= "stylesheet" type= "Text/css " href= "Styles.css" > -  </Head>    <Body>This is my JSP page. Success!!! <BR>    <!--normal attribute removal -    <Bean:writename= "message"/><BR>    <!--property of object type out -    <Bean:writename= "User" Property= "username"/><BR>    <Bean:writename= "User" Property= "Password"/><BR>    <Bean:writename= "User" Property= "CreateDate"format= "Yyyy-mm-dd HH:mm:ss"/><BR>    <HR>    <!--properties of list type out -    <logic:iterateID= "User"name= "UserList">        <Bean:writename= "User" Property= "username"/><BR>        <Bean:writename= "User" Property= "Password"/><BR>        <Bean:writename= "User" Property= "CreateDate"format= "Yyyy-mm-dd HH:mm:ss"/><BR>    </logic:iterate>    <HR>    <!--attributes of the map type are taken out -    <logic:iterateID= "Useriteam"name= "UserMap">        <Bean:writename= "Useriteam" Property= "Key"/><BR>        <Bean:writename= "Useriteam" Property= "Value.username"/><BR>        <Bean:writename= "Useriteam" Property= "Value.password"/><BR>        <Bean:writename= "Useriteam" Property= "Value.createdate"format= "Yyyy-mm-dd HH:mm:ss"/><BR>    </logic:iterate>  </Body></HTML>

STRUTS1 Four: Common labels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.