struts2_day01_14_Action的方法访问(使用method属性)

来源:互联网 发布:java abstract final 编辑:程序博客网 时间:2024/05/16 08:27

使用action标签method属性

1 创建action,创建多个方法

 

package com.hlg.action;import com.opensymphony.xwork2.ActionSupport;public class BookAction extends ActionSupport{public String add(){System.out.println("add.....");return NONE;}public String update(){System.out.println("update.....");return NONE;}}

2 使用method配置

 

<?xml version="1.0" encoding="UTF-8"?><!-- struts2约束 start --><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><!-- struts2约束 end --><struts><!-- 常量 -->    <constant name="struts.i18n.encoding" value="UTF-8"></constant>    <!-- <package name="hellodemo" extends="struts-default" namespace="/"> <action name="myhello" class="com.hlg.action.HelloAction"><result name="ok">/hello.jsp</result></action></package> --><!-- <include file="hello.xml"></include> --><package name="methoddemo" extends="struts-default" namespace="/"><action name="add" class="com.hlg.action.BookAction" method="add"></action><action name="update" class="com.hlg.action.BookAction" method="update"></action></package></struts>

缺陷:action每个方法都需要配置,如果action里面有多个方法,配置很多的action