DMI (Dynamic Method invocation)

Source: Internet
Author: User

Function:

Click Hello to invoke the Execute function

Click Update to call the update function

1. Project structure

2.web.xml

<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns: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

 Packagecom.action;ImportCom.opensymphony.xwork2.ActionSupport; Public classUseractionextendsActionsupport {Private Static Final Longserialversionuid=1l; PrivateString Info;  PublicString GetInfo () {returninfo; }     Public voidSetINfo (String info) { This. info=info; }     PublicString Execute ()throwsexception{Info= "Hello World bb!"; return"Hello"; }     PublicString Update ()throwsexception{Info= "ok,updated!"; return"Update"; }}

4.index.jsp

<%@ Pagelanguage= "Java"ContentType= "text/html; charset=utf-8"pageencoding= "UTF-8"%><%@ taglibprefix= "S"URI= "/struts-tags"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>    <Center>        <ahref= "User_execute">Hello</a><BR>        <ahref= "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.or G/dtds/struts-2.0.dtd "><Struts>    < Packagename= "Default"namespace="/"extends= "Struts-default">        <Actionname= "User_*"class= "Com.action.UserAction"Method= "{1}">            <resultname= "Hello">/hello.jsp</result>            <resultname= "Update">/update.jsp</result>        </Action>    </ Package></Struts>

6.hello.jsp

<%@ Pagelanguage= "Java"ContentType= "text/html; charset=utf-8"pageencoding= "UTF-8"%><%@ taglibprefix= "S"URI= "/struts-tags"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>    <Center>        <S:propertyvalue= "Info" />    </Center></Body></HTML>

7.update.jsp

<%@ Pagelanguage= "Java"ContentType= "text/html; charset=utf-8"pageencoding= "UTF-8"%><%@ taglibprefix= "S"URI= "/struts-tags"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>    <Center>        <S:propertyvalue= "Info" />    </Center></Body></HTML>

DMI (Dynamic Method invocation)

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.