Struts2 之 参数传递(一)

第一种:

类如下:

package com.laogaoge.front;

import com.opensymphony.xwork2.ActionSupport;

public class actionAttiParamInput extends ActionSupport{

    /**
     *
     */
    private static final long serialVersionUID = -5673235011931513331L;
   
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    private String name;
    private int age;
   
    public String add(){
        System.out.println("name="+name);
        System.out.println("age="+age);
        return SUCCESS;
    }
}

struts.xml的action

        <!-- 传递参数 -->
        <action name="useraction" class="com.laogaoge.front.actionAttiParamInput" >
            <result>
                /actionAttiParamInput/actionattiparaminput.jsp
            </result>
        </action>

 

jsp中的调用

<a href="front/useraction!add?name=a&age=8">添加用户</a>

你可能感兴趣的:(struts2)