我想在servlet中获取数据然后在初始化jsp页面时发送数据。 我有这样的网页:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<div>
<div>AAAAAAAAA</div>
<div>
<table border="1" id="table1">
${insert_data_here_1}
</table>
</div>
<div>BBBBBBBBBBB</div>
<div><table border="1" id="table2">${insert_data_here_2}</table></div>
<div>CCCCCCCCCCCCCC</div>
</div>
</body>
页面ExtendMasterPage扩展母版页。代码相同:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Extend</title>
</head>
<body>
<%
PageStack pS= new PageStack();
List<String> lstResult= pS.getData();
%>
<form action="PageStack" method="get">
<%@include file="masterPageStack.jsp" %>
<table border="1" id="table1">
<tr>
<td>
<%= lstResult.get(0) %>
</td>
</tr>
</table>
<table border="1" id="table2">
<tr>
<td>
<%= lstResult.get(1) %>
</td>
</tr>
</table>
</form>
</body>
并在页面ExtendMasterPage的servlet中编码。当我运行代码时,数据没有添加到insert_data_here_1和insert_data_here_2。我不明白为什么它不起作用?并解决这个问题?有人帮助我!
public List<String> getData(){
List<String> lstResult= new ArrayList<String>();
lstResult.add("Test1");
lstResult.add("Test2");
return lstResult;
}
答案 0 :(得分:0)
您没有填充变量并尝试使用它。你可以这样:
<%= session.setAttribute("insert_data_here_2", lstResult.get(1)); %>
而不是
<%= lstResult.get(1) %>