欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Struts2标签诡异问题

程序员文章站 2022-05-23 19:07:59
...

 

在测试struts2标签的时候遇到了一个问题,怎么想也想不明白

 

index.jsp

    <s:url var="aurl" namespace="/" action="aurl">
        <s:param name="number" value="zhaoyp" />
        <s:param name="password" value="123"/>
        <s:param name="age" value="11"/>
    </s:url>
    url:<s:property value="%{aurl}" />
    <s:a href="%{aurl}">s:a和s:url使用</s:a>

 

action:

public class AurlAction extends ActionSupport implements SessionAware {

	private static final long serialVersionUID = -795351427940115962L;

	private String number;
	
	private String password;
	
	private Integer age;
	
	private Map<String, Object> sessionMap;


	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String execute() throws Exception {
		System.out.println("number = " + number + " , password = " + password + ", age = " + age);
		sessionMap.put("number", number);
		sessionMap.put("password", password);
		sessionMap.put("age", age);
		return SUCCESS;
	}

	public void setSession(Map<String, Object> map) {
		Set<Map.Entry<String, Object>> set = map.entrySet();
		for (Iterator iterator = set.iterator(); iterator.hasNext();) {
			Entry<String, Object> entry = (Entry<String, Object>) iterator
					.next();
			System.out.println("key = " + entry.getKey() + " , value = " + entry.getValue());
			
		}
		sessionMap = map;
	}

	public Integer getAge() {
		return age;
	}

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

	public Map<String, Object> getSessionMap() {
		return sessionMap;
	}

	public void setSessionMap(Map<String, Object> sessionMap) {
		this.sessionMap = sessionMap;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

}

 

 

Struts.xml

 

        <action name="aurl" class="com.tag.action.AurlAction">
            <result name="success">aurl.jsp</result>
        </action>

 

 

输出页面:

<body>
    <s:debug />
    用户名:<s:property value="%{number}"/> <br>
   密码: <s:property value="%{password}"/><br>
   age:<s:property value="%{age}" /><br>
   session:<s:property value="%{sessionMap}"/>
</body>

 

我用的struts2.2.1,怎么都无法取到number的值,但是password和age就ok,sessionMap中也只有password和age,没有number