我使用Struts2的2.3.24,並試圖安裝該OGNL調用構造函數OGNL無法調用構造
package ac.nz.unitec.struts2;
public class User {
private String username;
private int age;
public User(String username, int age){
this.username = username;
this.age = age;
}
public User(int age){
this.age = age;
System.out.println("user");
}
public User(){}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "user " + age;
}
}
在JSP
一個demo,我打電話User
構造:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>OGNL</title>
</head>
<body>
zz
<s:property value="new ac.nz.unitec.struts2.User(28)"/><br>
zz
<s:debug/>
</body>
</html>
但是,輸出只顯示zz和zz,我不知道它有什麼問題。感謝您的任何建議
不要忘記接受/ upvote幫助你的答案。這將有助於未來的遊客也有類似的問題。 –
嗨,Aleksandr,如何接受?我upvoted然後,但沒有看到「接受」按鈕.. @AleksandrM – user1888955
閱讀http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work。 –