我的Action如下:
public class EditDeployAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
......
//将查询到的数据写入到session中,供页面使用
HttpSession httpSession = request.getSession();
httpSession.setAttribute("infoTable",pInfoTable);//pInfoTable为PlanSunProject的一个实例 ......
}
}我的页面代码如下,可是不能得到结果。谢谢
<body>
<form action="../../rzgs.do" enctype="multipart/form-data" method="post" id="inFrm" name="inFrm" target="mainwindow">
<%
if(request.getSession().getAttribute("infoTable")!=null)
{
PlanSunProject pInfoTable=(PlanSunProject)request.getSession().getAttribute("infoTable");//得到pInfoTable对象
}
%>
<script language="javascript">
alert(<%=String.valueOf(pInfoTable.getBuildingcompany())%>);
</script> <tr>
<td width="105" height="31"><font color='#003366' size='2'>项目名称:</td>
<td width="212"><textarea id="location" style="width:160px" name="projectName">
<%=pInfoTable.getProjectname()%></textarea></td>
</tr><input id="submitok" type="button" name="Submit" value="提交" onclick="SubmitOK()" />
<input id="reset" type="reset" name="reset" value="重填"/>
</form>
</body>
public class EditDeployAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
......
//将查询到的数据写入到session中,供页面使用
HttpSession httpSession = request.getSession();
httpSession.setAttribute("infoTable",pInfoTable);//pInfoTable为PlanSunProject的一个实例 ......
}
}我的页面代码如下,可是不能得到结果。谢谢
<body>
<form action="../../rzgs.do" enctype="multipart/form-data" method="post" id="inFrm" name="inFrm" target="mainwindow">
<%
if(request.getSession().getAttribute("infoTable")!=null)
{
PlanSunProject pInfoTable=(PlanSunProject)request.getSession().getAttribute("infoTable");//得到pInfoTable对象
}
%>
<script language="javascript">
alert(<%=String.valueOf(pInfoTable.getBuildingcompany())%>);
</script> <tr>
<td width="105" height="31"><font color='#003366' size='2'>项目名称:</td>
<td width="212"><textarea id="location" style="width:160px" name="projectName">
<%=pInfoTable.getProjectname()%></textarea></td>
</tr><input id="submitok" type="button" name="Submit" value="提交" onclick="SubmitOK()" />
<input id="reset" type="reset" name="reset" value="重填"/>
</form>
</body>
把一些代码注释掉,看看到底是不是页面代码的问题
最好看看Actioin是怎么定向的,返回的是不是requsest请求
if(request.getSession().getAttribute("infoTable")!=null)
{
PlanSunProject pInfoTable=(PlanSunProject)request.getSession().getAttribute("infoTable");//得到pInfoTable对象
}
%>
改为:
<%
PlanSunProject pInfoTable=new PlanSunProject();
if(request.getSession().getAttribute("infoTable")!=null)
{
pInfoTable=(PlanSunProject)request.getSession().getAttribute("infoTable");//得到pInfoTable对象
}
%> 你把对象定义在if里面,外面访问不了。