java框架

用通配符的方法配置action

第一步

创建一个action 在此action中不用实现或者继承(extents)任何类

在此action中编写所需要的方法,并提供必要返回值(这里并不一定要有返回值才行,也可以返回为空none  会自动调用struct里面的NONE)有传值时提供set get方法

public class LabelAction {

private String price;

private String msg;

public String propertyLabel(){

System.out.println(price);

  if("4.5".equals(price) || ("4.5元").equals(price)){

  

              msg="你是位贴心的男友,吃个墨西哥卷肯定不会让女朋友  出一分钱,看好你呦!";

        }else if("31.5".equals(price) || ("31.5元").equals(price)){

               msg="一个鸡肉卷这么贵,还有必要吃吗,败家!";

        }else              

               msg="少壮不努力,老大徒伤悲,这算数是咋算的";

       

  

  return  "propertyLabel";

}

 

 

 

public String getPrice() {

return price;

}

 

 

public void setPrice(String price) {

this.price = price;

}

 

 

public String getMsg() {

return msg;

}

 

 

public void setMsg(String msg) {

this.msg = msg;

}

}

 

第二步

配置structs.xml

主要配置:

<action name="labelAction_*" class="com.chinasoft.ssh.LabelAction"

 method="{1}">

 <result name="{1}">{1}.jsp</result>

 </action>

说明:action中的name用统配符的方式匹配(为了规范和避免混淆 这个名字与action的类名相同然后加上_**号就是propertyLabel方法(即提交过来的方法)

     ②method{1};

 ③result 中的name {1};这里的{1},就是从容器中获取到的具体方法

第三步

 

 

jsp页面 :

进入actioneg:表单提交方式:

    <form action="labelAction_propertyLabel.action" method="post">

    <div class="bg">

    <p>

有一个墨西哥鸡肉卷,你的女朋友吃了3/7,你吃掉了剩下的

           4/7,你比你的女朋友多出了4.5元钱,

           请问这个墨西哥鸡肉卷的价格是多少钱?    

    </p>

    <p class="as">

    <input class="price" type="text" name="price">

    </p>

    <p><input type="submit" value="提交"></p>

    </div>

    </form>

 

 

 

 

展示从action中获取的值两种展示方法:一,el表达式;二,导入<%@taglib  prefix="s" uri="/struts-tags"%>,实现:<s:property value="msg"/>

 

 

执行过程:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值