I have a search form(name = studentForm) that is submitted to struts2 action which fetches data from db and returns to a JSP with a form (name = studentListForm).
When I use s:property, I'm able to get a property from the action form, whereas with EL is empty.
Action
private int pageNumber;
/** some code here **/
setPageNumber(1);
public int getPageNumber()
{
return pageNumber;
}
public void setPageNumber(int pageNumber)
{
this.pageNumber = pageNumber;
}
JSP
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<s:form id="studentListForm" name="studentListForm" action="student.do" method="post" class="pure-form pure-form-aligned">
<table width="50%">
<tr>
<td align="center" colspan="2">
<!-- This works -->
<s:property value="pageNumber"/>
<!-- This doesn't -->
<c:out value="${studentListForm.pageNumber}"></c:out>
</td>
</tr>
</table>
<div id="hiddenFields">
<s:hidden key="pageNumber"></s:hidden>
</div>
</s:form>
</html>
You need to change EL to find your action variable in the valueStack
.
<c:out value="${pageNumber}"/>
Note, that EL expressions should have access to valueStack
variables due to Struts request wrapper. See How we use JSTL with the framework.