Wu Yuxiong - natural born flyweight JAVA EE enterprise application development Struts2Sping4Hibernate integrated development study notes: Using Struts2 tag library - Data Labels

<?xml version="1.0" encoding="GBK"?>
<project name="struts" basedir="." default="">
    <property name="dist" value="classes"/>
    <property name="src" value="src"/>
    
    <path id="classpath">
        <fileset dir="lib">
            <include name="*.jar"/>
        </fileset>
        <pathelement path="${dist}"/>
    </path>

    <target name="compile" description="Compile all source code">
        <delete dir="${dist}"/>
        <mkdir dir="${dist}"/>
        <copy todir="${dist}">
            <fileset dir="${src}">
                <exclude name="**/*.java"/>
            </fileset>        
        </copy>
        <javac destdir="classes" debug="true" includeantruntime="yes"
            deprecation="false" optimize="false" failonerror="true">
            <src path="${src}"/>
            <classpath refid="classpath"/>
        </javac>
    </target>

</project>
<?xml version="1.0" encoding="GBK"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">

    <! - define the core of Filter Struts 2 ->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <! - let Struts core Filter 2 intercept all requests ->
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <constant name="struts.i18n.encoding" value="GBK"/>

    <package name="lee" extends="struts-default">
        <! - Define the first Action, the use TagAction
            As a method to control processing logic execute ->
        <action name="tag1" class="org.crazyit.app.action.TagAction">
            <result name="done">/WEB-INF/content/succ.jsp</result>
        </action>
        <! - definition of a second Action, the use TagAction
            As a method to control processing logic login ->
        <action name="tag2" class="org.crazyit.app.action.TagAction"
            method="login">
            <result name="done">/WEB-INF/content/loginSucc.jsp</result>
        </action>
        <action name="*">
            <result>/WEB-INF/content/{1}.jsp</result>
        </action>
    </package>
</struts>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> included page </ title>
</head>
<body>
<H3> Page </ h3> is included
author parameter values ​​are: $ {param.author}
</body>
</html>
<%--
 @ YeekuHlee kongyeeku author of 163 * the .com
  * version 1.0 for
 * <br/>Copyright (C), 2005-2008, yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date: 
--%>
<%@ page contentType="text/html; charset=GBK" language="java"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<Title> s: action success Page </ title>
</head>
<body>
<br/>
<S: Property value = "author" /> , log on success! !
</ body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Use s: action tag call Action </ title> in the page
</head>
<body> 
calls the first Action below, and the results are included in the present page. <br/>
<s:action name="tag1" executeResult="true"/>
<hr /> 
The following call to the second Action, and the results are included in the present page. <br/> 
but prevents this incoming page request parameter Action. <br/>
<s:action name="tag2" executeResult="true"
    ignoreContextParams="true"/>
<hr /> 
The following call a third Action, and the results are not included on this page. <br/>
<s: action name = "tag2 " executeResult = "false" /> 
This page is accessible? <s: property value = "author " />
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Use s: bean JavaBean create an instance of the tag </ title>
</head>
<body>
<! - Create an instance of a Person class using bean tag ->
<s:bean name="org.crazyit.app.dto.Person">
    <! - Use param tags for instance of the Person class parameter passed ->
    <s:param name="name" value="'yeeku'"/>
    <s:param name="age" value="29"/>
    <! - as bean in the label, the Person instance is ValueStack top of the stack,
        It is possible to directly access lee.Person Examples -> 
    the Person instance name as: <S: Property value = "name" /> a 
    Age of the Person instance: <S: Property value = "Age" />
</s:bean>
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Use s: bean JavaBean create an instance of the tag </ title>
</head>
<body>
<! - Use bean tag to create an instance of the Person class, assign the attribute var ->
<s:bean name="org.crazyit.app.dto.Person" var="p">
    <! - Use param tags for instance of the Person class parameter passed ->
    <s:param name="name" value="'yeeku'"/>
    <s:param name="age" value="29"/>
</s:bean>
<! - example of an access JavaBean JavaBean instance attributes specified var -> 
the Person instance name as: <S: Property value = "# p.name" /> a 
the Person instance age to: <S : property value = "# p.age" /> <br/>
${requestScope.p}
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Use s: date format date tag </ title>
</head>
<body>
<s:bean var="now" name="java.util.Date"/>
nice="false",且指定format="dd/MM/yyyy"<br/>
<s:date name="#now" format="dd/MM/yyyy" nice="false"/><hr/>
nice="true",且指定format="dd/MM/yyyy"<br/>
<s:date name="#now" format="dd/MM/yyyy" nice="true"/><hr/>
指定nice="true"<br/>
<s:date name="#now" nice="true" /><hr/>
nice="false",且没有指定format属性<br/>
<S: DATE name = "# now" Nice = "to false" /> <HR /> 
Nice = "to false", do not specify the format attribute, specifies var <br/>
<s:date name="#now" nice="false" var="abc"/><hr/>
${requestScope.abc} <s:property value="#abc"/>
</body>
</html>
<%--
 @ YeekuHlee kongyeeku author of 163 * the .com
  * version 1.0 for
 * <br/>Copyright (C), 2005-2008, yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date: 
--%>
<%@ page contentType="text/html; charset=GBK" language="java"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<Title> Use s: bean JavaBean create an instance of the tag </ title>
</head>
<body>
<s:bean name="lee.Person" id="p">
    <s:param name="name" value="'yeeku'"/>
    <s:param name="age" value="29"/>
</s:bean>
<s:property value="#p.name"/><br/>
<s:property value="#p.age"/>
<s:debug/>
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Use s: include tag to include the target page </ title>
</head>
<body>
<H2> Use s: include tag to include the target page </ h2>
<! - use include tag to include another page ->
<s:include value="included-file.jsp"/>
<! - include the use of labels to include other pages, and passing parameters ->
<s:include value="included-file.jsp">
    <s:param name="author" value="'yeeku'"/>
</s:include>
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Use s: push a value to the top of the stack into ValueStack </ title>
</head>
<body>
<H2> Use s: push to the top of the stack into a value of ValueStack </ h2>
<! - Use bean tag to create a JavaBean instance,
    Var attribute specified, and placed into the Stack Context ->
<s:bean name="org.crazyit.app.dto.Person" var="p">
    <s:param name="name" value="'yeeku'"/>
    <s:param name="age" value="29"/>
</s:bean>
<! - p-Stack Context objects placed in the top of the stack ValueStack ->
<s:push value="#p">
    <- - ValueStack output stack object attribute name and age!> 
    Name attribute ValueStack stack objects: <S: Property value = "name" /> a 
    ValueStack stack object age attribute: <S : property value = "age" / > <br/>
</s:push>
</body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Use s: set a new variable set </ title>
</head>
<body>
<H2> Use s: set a new variable set </ h2>
<! - a JavaBean instance bean tag definitions ->
<s:bean name="org.crazyit.app.dto.Person" id="p">
    <s:param name="name" value="'yeeku'"/>
    <s:param name="age" value="29"/>
</ s: bean> 
p-value Stack Context placed in the default range (action) inside. <br/>
<S: SET value = "P #" name = "XXX" /> 
name attribute of the object within the Stack Context xxx: <S: Property value = "# xxx.name" /> a 
within subject Stack Context xxx age property: <S: property value = "xxx.age #" /> a 
name property of the object request xxx range: $ {} requestScope.xxx.name a 
age attribute request xxx target range : $ {requestScope.xxx.age} <HR /> 
p-values into the Stack Context in the application range. <br/>
<S: SET value = "P #" name = "yyy" scope = "application" /> 
name attribute yyy target application range: $ {} applicationScope.yyy.name a 
Age range of application objects yyy properties: applicationScope.yyy.age} {$ <HR /> 
p-value Stack Context placed in the session scope. <br/>
<S: SET value = "P #" name = "zzz" scope = "session" /> 
name attribute zzz session target range: $ {} sessionScope.zzz.name a
zzz session target age attribute range: $ {sessionScope.zzz.age}
</body>
</html>
<%--
 @ YeekuHlee kongyeeku author of 163 * the .com
  * version 1.0 for
 * <br/>Copyright (C), 2005-2008, yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date: 
--%>
<%@ page contentType="text/html; charset=GBK" language="java"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<Title> s: action success Page </ title>
</head>
<body>
<br/>
<S: Property value = "author" /> , the successful implementation! !
</ body>
</html>
<% - 
Web site: <A href = "http://www.crazyit.org"> crazy league Java </a> 
author yeeku.H.lee kongyeeku @ 163 .com
which version of the   1.0 for 
Amsterdam Copyright (the C), 20012016 , yeekuHLee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <Title> Use s: url URL address to generate a </ title>
</head>
<body>
<h2> s: url generates a URL address </ h2> 
specify only the form of the value attribute. <br/>
<s:url value="editGadget.action"/>
<hr /> 
Specifies the action attribute, and using the parameters passed in the form of param. <br/>
<s:url action="showBook">
    <s:param name="author" value="'yeeku'" />
</s:url>
<hr /> 
specify neither action attribute, attribute value is assigned, but the use form param arguments passed. <br/>
<s:url includeParams="get"  >
    <s:param name="id" value="%{'22'}"/>
</s:url>
<hr /> 
specify action attribute and attribute value, and using the parameters passed in the form of param. <br/>
<s:url action="showBook" value="xxxx">
    <s:param name="author" value="'yeeku'" />
</s:url>
</body>
</html>
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <constant name="struts.i18n.encoding" value="GBK"/>

    <package name="lee" extends="struts-default">
        <! - Define the first Action, the use TagAction
            As a method to control processing logic execute ->
        <action name="tag1" class="org.crazyit.app.action.TagAction">
            <result name="done">/WEB-INF/content/succ.jsp</result>
        </action>
        <! - definition of a second Action, the use TagAction
            As a method to control processing logic login ->
        <action name="tag2" class="org.crazyit.app.action.TagAction"
            method="login">
            <result name="done">/WEB-INF/content/loginSucc.jsp</result>
        </action>
        <action name="*">
            <result>/WEB-INF/content/{1}.jsp</result>
        </action>
    </package>
</struts>
package org.crazyit.app.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;

/**
 * Description:
 * <br/> website: <a href=" http://www.crazyit.org "> crazy Java league </a>
 * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * Author   YeekuHLee kongyeeku163com
 * @version  1.0
 */
public class TagAction extends ActionSupport
{
    // author package member variables of a user request parameter 
    Private String author;

    // author of setter and getter methods 
    public  void setAuthor (String author)
    {
        this.author = author;
    }
    public String getAuthor()
    {
        return this.author;
    }
    // define the first processing logic 
    public String Execute () throws Exception
    {
        return "done";
    }
    // define a second logic processing 
    public String Login () throws Exception
    {
        ActionContext.getContext().
            put("author", getAuthor());
        return "done";
    }
}
package org.crazyit.app.dto;

/**
 * Description:
 * <br/> website: <a href=" http://www.crazyit.org "> crazy Java league </a>
 * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * Author   YeekuHLee kongyeeku163com
 * @version  1.0
 */
public class Person
{
    private String name;
    private int age;

    // setter and getter method name of 
    public  void setName (String name)
    {
        this.name = name;
    }
    public String getName()
    {
        return this.name;
    }

    // Age of setter and getter methods 
    public  void setAge ( int Age)
    {
        this.age = age;
    }
    public int getAge()
    {
        return this.age;
    }
}

 

Guess you like

Origin www.cnblogs.com/tszr/p/12364706.html