Struts 2中的EL无法正常工作 [英] EL in struts 2 not working
问题描述
我有一个搜索表单(名称= studentForm),该表单被提交给struts2动作,该动作从db中获取数据并返回给表单(名称= studentListForm)的JSP.
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).
使用s:property时,我可以从操作表单中获取属性,而EL为空.
When I use s:property, I'm able to get a property from the action form, whereas with EL is empty.
动作
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>
推荐答案
您需要更改EL才能在valueStack
中找到操作变量.
You need to change EL to find your action variable in the valueStack
.
<c:out value="${pageNumber}"/>
请注意,由于Struts请求包装程序,EL表达式应有权访问valueStack
变量.请参见我们如何在框架中使用JSTL .
Note, that EL expressions should have access to valueStack
variables due to Struts request wrapper. See How we use JSTL with the framework.
这篇关于Struts 2中的EL无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!