Dynamic Method Invocation

Source: Internet
Author: User

1. Create a project first

2. Two jsps need to be created in this project

1) Write a sentence in the first JSP

<body>user ADD success!</body>

2) write a link in the second JSP

<body>action does not have to execute the Execute method <br/> can configure the action in the configuration file with method= To specify which method to execute or dynamically specify in the URL address (dynamic method call DMI) (recommended) <br/><a href= "<%=context%>/user/useradd" > Add Users </a> <BR/><a href= "<%=context%>/user/user!add" > Add user </a><br/> The former will generate too much action, so it is not recommended to use < /body>

3.java Backstage

public class Useraction extends Actionsupport {public String Add () {return SUCCESS;}

This function adds a user

4. Write in Struts.xml

<struts>    <constant name= "Struts.devmode" value= "true"/>    <package name= "user" extends= " Struts-default "namespace="/user ">        <action name=" UserAdd "class=" Com.bjsxt.struts2.user.action.UserAction "method=" Add ">            <result>/user_add_success.jsp</result >        </action>                <action name= "user" class= "com.bjsxt.struts2.user.action.UserAction" >            <result>/user_add_success.jsp</result>        </action>    </package></struts>

For page jumps

5. Finally, please do not forget to write this sentence in Web. xml

   <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>

  

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.