zoukankan      html  css  js  c++  java
  • DMI ( Dynamic Method Invocation )

    功能:

    点击 hello , 调用 execute 函数

    点击 update , 调用 update 函数

    1.项目结构

    2.web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
      <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>

    3.UserAction.java

    package com.action;
    import com.opensymphony.xwork2.ActionSupport;
    
    public class UserAction extends ActionSupport {
        private static final long serialVersionUID=1L;
        private String info;
        public String getInfo()
        {
            return info;
        }
        public void setINfo(String info)
        {
            this.info=info;
        }
        public String execute() throws Exception{
            info="hello world bb!";
            return "hello";
        }
        public String update() throws Exception{
            info="ok,updated!";
            return "update";
        }
    }

    4.index.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
        <center>
            <a href="user_execute">hello</a><br>
            <a href="user_update">update</a>
        </center>
    </body>
    </html>

    5.struts.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        <package name="default" namespace="/" extends="struts-default">
            <action name="user_*" class="com.action.UserAction" method="{1}">
                <result name="hello">/hello.jsp</result>
                <result name="update">/update.jsp</result>
            </action>
        </package>
    </struts>

    6.hello.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
        <center>
            <s:property value="info" />
        </center>
    </body>
    </html>

    7.update.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
        <center>
            <s:property value="info" />
        </center>
    </body>
    </html>
  • 相关阅读:
    7月30日 举办专注于微服务的.NET Conf Focus
    我和ABP vNext 的故事
    Windows环境搞好的Dockerfile文件 在Linux上报错了
    [LeetCode] 955. Delete Columns to Make Sorted II 删除列使其有序之二
    [LeetCode] 954. Array of Doubled Pairs 两倍数对儿数组
    上周热点回顾(8.3-8.9)团队
    发布新版首页“外婆新家”升级版:全新的UI,熟悉的味道团队
    上周热点回顾(7.27-8.2)团队
    终于换新颜:新版网站首页发布上线团队
    上周热点回顾(7.20-7.26)团队
  • 原文地址:https://www.cnblogs.com/c0liu/p/5495676.html
Copyright © 2011-2022 走看看