Java PropertyNotFoundException:Property';X';在类型X上找不到
我有Java PropertyNotFoundException:Property';X';在类型X上找不到,java,jsp,struts2,jstl,Java,Jsp,Struts2,Jstl,我有viewprofile操作,显示用户的详细信息和交易历史记录 History.java: public class History { private String transactionId; private Date transactionDate; private String movieTitle; private BigDecimal schedulePrice; private String mallName; private i
viewprofile
操作,显示用户的详细信息和交易历史记录
History.java
:
public class History {
private String transactionId;
private Date transactionDate;
private String movieTitle;
private BigDecimal schedulePrice;
private String mallName;
private int scheduleCinema;
private Date scheduleDate;
private Time scheduleTime;
// getters and setters
}
public class ViewProfileAction extends ActionSupport implements SessionAware, RequestAware {
private static final long serialVersionUID = 1L;
private Map<String, Object> session;
private Map<String, Object> request;
@Override
public String execute() throws Exception {
if(!session.containsKey("currentUserId")) {
return "index"; // return to index if not logged in
}
String currentUserId = (String) session.get("currentUserId");
UserManager um = new UserManager();
String registeredUserEmail = um.getCurrentUserDetail("user_email", currentUserId);
Date registeredDate = um.getRegisteredDate(currentUserId);
int totalTransactions = um.getTotalTransactions(currentUserId);
List<History> historyList = new DatabaseManipulator().getTransactionHistory(currentUserId);
request.put("registeredUserEmail", registeredUserEmail);
request.put("registeredDate", registeredDate);
request.put("totalTransactions", totalTransactions);
request.put("historyList", historyList);
return SUCCESS;
}
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}
@Override
public void setRequest(Map<String, Object> request) {
this.request = request;
}
}
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<body>
<table class="displaytbl">
<tr>
<td class="maintitle" colspan="7">TRANSACTION HISTORY</td>
</tr>
<tr>
<!-- column titles -->
</tr>
<c:choose>
<c:when test="${historyList.isEmpty()}">
<tr>
<td class="norecord" colspan="7">NO RECORDED TRANSACTIONS</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach var="history" items="historyList">
<tr>
<td>${history.transactionDate}</td>
<td>${history.movieTitle}</td>
<td>${history.schedulePrice}</td>
<td>${history.mallName}</td>
<td class="center">${history.scheduleCinema}</td>
<td>${history.scheduleDate}</td>
<td>${history.scheduleTime}</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
</body>
<action name="viewprofile" class="com.mypackage.action.ViewProfileAction">
<result>/user-profile.jsp</result>
<result name="index" type="redirect">/index.jsp</result>
</action>
javax.el.PropertyNotFoundException: Property 'transactionDate' not found on type java.lang.String
ViewProfileAction.java
:
public class History {
private String transactionId;
private Date transactionDate;
private String movieTitle;
private BigDecimal schedulePrice;
private String mallName;
private int scheduleCinema;
private Date scheduleDate;
private Time scheduleTime;
// getters and setters
}
public class ViewProfileAction extends ActionSupport implements SessionAware, RequestAware {
private static final long serialVersionUID = 1L;
private Map<String, Object> session;
private Map<String, Object> request;
@Override
public String execute() throws Exception {
if(!session.containsKey("currentUserId")) {
return "index"; // return to index if not logged in
}
String currentUserId = (String) session.get("currentUserId");
UserManager um = new UserManager();
String registeredUserEmail = um.getCurrentUserDetail("user_email", currentUserId);
Date registeredDate = um.getRegisteredDate(currentUserId);
int totalTransactions = um.getTotalTransactions(currentUserId);
List<History> historyList = new DatabaseManipulator().getTransactionHistory(currentUserId);
request.put("registeredUserEmail", registeredUserEmail);
request.put("registeredDate", registeredDate);
request.put("totalTransactions", totalTransactions);
request.put("historyList", historyList);
return SUCCESS;
}
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}
@Override
public void setRequest(Map<String, Object> request) {
this.request = request;
}
}
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<body>
<table class="displaytbl">
<tr>
<td class="maintitle" colspan="7">TRANSACTION HISTORY</td>
</tr>
<tr>
<!-- column titles -->
</tr>
<c:choose>
<c:when test="${historyList.isEmpty()}">
<tr>
<td class="norecord" colspan="7">NO RECORDED TRANSACTIONS</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach var="history" items="historyList">
<tr>
<td>${history.transactionDate}</td>
<td>${history.movieTitle}</td>
<td>${history.schedulePrice}</td>
<td>${history.mallName}</td>
<td class="center">${history.scheduleCinema}</td>
<td>${history.scheduleDate}</td>
<td>${history.scheduleTime}</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
</body>
<action name="viewprofile" class="com.mypackage.action.ViewProfileAction">
<result>/user-profile.jsp</result>
<result name="index" type="redirect">/index.jsp</result>
</action>
javax.el.PropertyNotFoundException: Property 'transactionDate' not found on type java.lang.String
struts.xml
:
public class History {
private String transactionId;
private Date transactionDate;
private String movieTitle;
private BigDecimal schedulePrice;
private String mallName;
private int scheduleCinema;
private Date scheduleDate;
private Time scheduleTime;
// getters and setters
}
public class ViewProfileAction extends ActionSupport implements SessionAware, RequestAware {
private static final long serialVersionUID = 1L;
private Map<String, Object> session;
private Map<String, Object> request;
@Override
public String execute() throws Exception {
if(!session.containsKey("currentUserId")) {
return "index"; // return to index if not logged in
}
String currentUserId = (String) session.get("currentUserId");
UserManager um = new UserManager();
String registeredUserEmail = um.getCurrentUserDetail("user_email", currentUserId);
Date registeredDate = um.getRegisteredDate(currentUserId);
int totalTransactions = um.getTotalTransactions(currentUserId);
List<History> historyList = new DatabaseManipulator().getTransactionHistory(currentUserId);
request.put("registeredUserEmail", registeredUserEmail);
request.put("registeredDate", registeredDate);
request.put("totalTransactions", totalTransactions);
request.put("historyList", historyList);
return SUCCESS;
}
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}
@Override
public void setRequest(Map<String, Object> request) {
this.request = request;
}
}
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<body>
<table class="displaytbl">
<tr>
<td class="maintitle" colspan="7">TRANSACTION HISTORY</td>
</tr>
<tr>
<!-- column titles -->
</tr>
<c:choose>
<c:when test="${historyList.isEmpty()}">
<tr>
<td class="norecord" colspan="7">NO RECORDED TRANSACTIONS</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach var="history" items="historyList">
<tr>
<td>${history.transactionDate}</td>
<td>${history.movieTitle}</td>
<td>${history.schedulePrice}</td>
<td>${history.mallName}</td>
<td class="center">${history.scheduleCinema}</td>
<td>${history.scheduleDate}</td>
<td>${history.scheduleTime}</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
</body>
<action name="viewprofile" class="com.mypackage.action.ViewProfileAction">
<result>/user-profile.jsp</result>
<result name="index" type="redirect">/index.jsp</result>
</action>
javax.el.PropertyNotFoundException: Property 'transactionDate' not found on type java.lang.String
我不知道当我在
历史记录中确实有所述属性时,它为什么会抛出属性NotFoundException
。如何解决这样的问题?似乎是Jsp页面中下面一行的问题<代码>历史记录
将仅指向纯字符串历史列表
,而不是您的集合对象
<c:forEach var="history" items="historyList">
上面的no where将在下面访问,您可能需要使用
在Jsp页面的下面一行似乎有问题<代码>历史记录将仅指向纯字符串
历史列表
,而不是您的集合对象
<c:forEach var="history" items="historyList">
上面的no where将在下面访问,您可能需要使用
您完全绕过了框架机制;不要使用
请求
,而是将私有属性与getter和setter一起使用:
public class ViewProfileAction extends ActionSupport implements SessionAware {
private static final long serialVersionUID = 1L;
private Map<String, Object> session;
private List<History> historyList;
private String registeredUserEmail;
private Date registeredDate;
private int totalTransactions;
/* Generate GETTERS AND SETTERS for above fields here */
@Override
public String execute() throws Exception {
if(!session.containsKey("currentUserId")) {
return "index"; // return to index if not logged in
}
String currentUserId = (String) session.get("currentUserId");
UserManager um = new UserManager();
registeredUserEmail = um.getCurrentUserDetail("user_email", currentUserId);
registeredDate = um.getRegisteredDate(currentUserId);
totalTransactions = um.getTotalTransactions(currentUserId);
historyList = new DatabaseManipulator().getTransactionHistory(currentUserId);
return SUCCESS;
}
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}
}
public类ViewProfileAction扩展了ActionSupport实现了SessionAware{
私有静态最终长serialVersionUID=1L;
私人Map会议;
私人名单史学家;
私有字符串注册器;
私人日期登记日期;
私人交易;
/*在此处为上述字段生成getter和setter*/
@凌驾
公共字符串execute()引发异常{
如果(!session.containsKey(“currentUserId”)){
return“index”;//如果未登录,则返回到index
}
String currentUserId=(String)session.get(“currentUserId”);
UserManager um=newusermanager();
registeredUserEmail=um.getCurrentUserDetail(“用户电子邮件”,currentUserId);
registeredDate=um.getRegisteredDate(currentUserId);
totalTransactions=um.getTotalTransactions(currentUserId);
historyList=新数据库操纵器().getTransactionHistory(currentUserId);
回归成功;
}
@凌驾
公共无效设置会话(映射会话){
this.session=会话;
}
}
另外,避免使用JSPEL和减少JSTL和Struts2标记+OGNL的功能,这将是Struts2项目中的完美选择
会话中的用户检查可以在拦截器中执行一次,而无需在项目的每个操作中都进行检查;阅读如何操作。您完全绕过了框架机制;不要使用
请求
,而是将私有属性与getter和setter一起使用:
public class ViewProfileAction extends ActionSupport implements SessionAware {
private static final long serialVersionUID = 1L;
private Map<String, Object> session;
private List<History> historyList;
private String registeredUserEmail;
private Date registeredDate;
private int totalTransactions;
/* Generate GETTERS AND SETTERS for above fields here */
@Override
public String execute() throws Exception {
if(!session.containsKey("currentUserId")) {
return "index"; // return to index if not logged in
}
String currentUserId = (String) session.get("currentUserId");
UserManager um = new UserManager();
registeredUserEmail = um.getCurrentUserDetail("user_email", currentUserId);
registeredDate = um.getRegisteredDate(currentUserId);
totalTransactions = um.getTotalTransactions(currentUserId);
historyList = new DatabaseManipulator().getTransactionHistory(currentUserId);
return SUCCESS;
}
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}
}
public类ViewProfileAction扩展了ActionSupport实现了SessionAware{
私有静态最终长serialVersionUID=1L;
私人Map会议;
私人名单史学家;
私有字符串注册器;
私人日期登记日期;
私人交易;
/*在此处为上述字段生成getter和setter*/
@凌驾
公共字符串execute()引发异常{
如果(!session.containsKey(“currentUserId”)){
return“index”;//如果未登录,则返回到index
}
String currentUserId=(String)session.get(“currentUserId”);
UserManager um=newusermanager();
registeredUserEmail=um.getCurrentUserDetail(“用户电子邮件”,currentUserId);
registeredDate=um.getRegisteredDate(currentUserId);
totalTransactions=um.getTotalTransactions(currentUserId);
historyList=新数据库操纵器().getTransactionHistory(currentUserId);
回归成功;
}
@凌驾
公共无效设置会话(映射会话){
this.session=会话;
}
}
另外,避免使用JSPEL和减少JSTL和Struts2标记+OGNL的功能,这将是Struts2项目中的完美选择
会话中的用户检查可以在拦截器中执行一次,而无需在项目的每个操作中都进行检查;阅读如何。我已更改为
items=“${historyList}”
,现在可以使用了。我真傻。投票表决通过并被接受为答案。为我的错误感到抱歉。@ohtph这有时会发生。:)我已更改为items=“${historyList}”
,现在可以使用了。我真傻。投票表决通过并被接受为答案。为我的错误感到抱歉。@ohtph这有时会发生。:)您好,这是否意味着如果我将${}
更改为
,它将抵御XSS攻击?没错。如果你把它改成
,我的天啊,我得改变很多。哈哈哈。非常感谢Andrea,老实说,我不确定XSS到底是如何执行的,但我们的web项目将在国防/决赛日进行“XSS”测试。我现在就开始修改,谢谢你的提示。(顺便说一句,我对你的答案投了赞成票)你也应该在这个答案中获得其他建议:你现在正在使用Struts2框架的10%。:|P.S:如果你发现XSS的答案是有用的,请考虑它的投票,谢谢,这是否意味着如果我改变了我的<代码> ${} /代码>到<代码> <代码>它会阻止XSS攻击?如果你把它改成
,我的天啊,我得改变很多。哈哈哈。非常感谢Andrea,老实说,我不确定XSS到底是如何执行的,但我们的web项目将在国防/决赛日进行“XSS”测试。我现在就开始修改,谢谢你的提示。(顺便说一句,我对你的答案投了赞成票)你也应该在这个答案中获得其他建议:你现在正在使用Struts2框架的10%。:|P.S:如果你发现XSS的答案有用,请考虑投票,谢谢。