zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:Struts2的类型转换:基于OGNL的类型转换(3)

    <?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">
        <!-- 定义Struts 2的核心Filter -->
        <filter>
            <filter-name>struts2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
        <!-- 让Struts 2的核心Filter拦截所有请求 -->
        <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>
        <package name="lee" extends="struts-default">
            <action name="login" class="org.crazyit.app.action.LoginAction">
                <result>/WEB-INF/content/welcome.jsp</result>
                <result name="error">/WEB-INF/content/welcome.jsp</result>
            </action>
            <action name="*">
                <result>/WEB-INF/content/{1}.jsp</result>        
            </action>
        </package>
    </struts>
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    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>直接封装成Map</title>
    </head>
    <body>
    <h3>直接封装成Map</h3>
    <s:form action="login">
        <s:textfield name="users['one'].name" label="第one个用户名"/>
        <s:textfield name="users['one'].pass" label="第one个密码"/>
        <s:textfield name="users['two'].name" label="第two个用户名"/>
        <s:textfield name="users['two'].pass" label="第two个密码"/>
        <tr>
            <td colspan="2"><s:submit value="转换" theme="simple"/>
            <s:reset value="重填" theme="simple"/></td>
        </tr>
    </s:form>
    </body>
    </html>
    <%--
    网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
    author  yeeku.H.lee kongyeeku@163.com
    version  1.0
    Copyright (C), 2001-2016, yeeku.H.Lee
    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>转换结果</title>
    </head>
    <body>
        <s:actionmessage/>
        key为one的用户名为:<s:property value="users['one'].name"/><br/>
        key为one的密码为:<s:property value="users['one'].pass"/><br/>
        key为two的用户名为:<s:property value="users['two'].name"/><br/>
        key为two的密码为:<s:property value="users['two'].pass"/><br/>
    </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>
        <package name="lee" extends="struts-default">
            <action name="login" class="org.crazyit.app.action.LoginAction">
                <result>/WEB-INF/content/welcome.jsp</result>
                <result name="error">/WEB-INF/content/welcome.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 java.util.Map;
    
    import org.crazyit.app.domain.*;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    public class LoginAction extends ActionSupport
    {
        // Action类里包含一个Map类型的成员变量
        // Map的value类型为User类型
        private Map<String , User> users;
    
        // users的setter和getter方法
        public void setUsers(Map<String , User> users)
        {
            this.users = users;
        }
        public Map<String , User> getUsers()
        {
            return this.users;
        }
    
        public String execute() throws Exception
        {
            // 在控制台输出Struts 2封装产生的Map对象
            System.out.println(getUsers());
            // 根据Map集合中key为one的User实例来决定控制逻辑
            if (getUsers().get("one").getName().equals("crazyit.org")
                && getUsers().get("one").getPass().equals("leegang") )
            {
                addActionMessage("登录成功!");
                return SUCCESS;
            }
            addActionMessage("登录失败!!");
            return ERROR;
        }
    }
    package org.crazyit.app.domain;
    
    /**
     * Description:
     * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
     * <br/>Copyright (C), 2001-2016, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author  Yeeku.H.Lee kongyeeku@163.com
     * @version  1.0
     */
    public class User
    {
        private String name;
        private String pass;
    
        // name的setter和getter方法
        public void setName(String name)
        {
            this.name = name;
        }
        public String getName()
        {
            return this.name;
        }
    
        // pass的setter和getter方法
        public void setPass(String pass)
        {
            this.pass = pass;
        }
        public String getPass()
        {
            return this.pass;
        }
    }
  • 相关阅读:
    CODING x 百果园 _ 水果零售龙头迈出 DevOps 体系建设第一步
    Nocalhost 亮相 CD Foundation 国内首届 Meetup,Keith Chan 将出席致辞
    做云原生时代标准化工具,实现高效云上研发工作流
    打造数字化软件工厂 —— 一站式 DevOps 平台全景解读
    WePack —— 助力企业渐进式 DevOps 转型
    CODING Compass —— 打造行云流水般的软件工厂
    Nocalhost —— 让云原生开发回归原始而又简单
    CODING 代码资产安全系列之 —— 构建全链路安全能力,守护代码资产安全
    Nocalhost:云原生开发新体验
    使用 Nocalhost 开发 Kubernetes 中的 APISIX Ingress Controller
  • 原文地址:https://www.cnblogs.com/tszr/p/12364817.html
Copyright © 2011-2022 走看看