简单的struts2框架(三)动态调用

相对于上篇博客《简单的struts2框架(二)》的改变,action的动态调用:

在struts.xml方法调用

1 <action name="userAction_*" class="action.UserAction" method="{1}">
2     <result name="success" type="dispatcher">/user/Success.jsp</result>
3     <result name="error" type="dispatcher">/user/Error.jsp</result>
4     <result name="reg_success" type="dispatcher">/user/UserLogin.jsp</result>
5 </action>

*代表的是action里相对应的方法, method="{1}"的值是第一个*的值,然后根据不同的result的那么执行不同的jsp

同时相对应的jsp也要改变:

<form action="/practice_struts2/useruserAction_doRegister.action" method="post">
    
        用户名:<input name="username" type="text"><br/>
        密    码:<input name="userpwd" type="password"><br/>
        出生日期:<input name="birthDate" type="text">yyyy-MM-dd<br/>
        <input type="submit" value="注册"/><input type="reset" value="重置"/>
</form>

从jsp和struts.xml可以清楚的看出:*代表的是doRegister方法

原文地址:https://www.cnblogs.com/jiuqing/p/4045207.html