1. 从一个 JSP 页面跳转到另一个 JSP 页面时的参数传递

1)使用 request 内置对象获取客户端提交的信息

2)使用 session 对象获取客户端提交的信息

3)利用隐藏域传递数据

4)通过超链接传递数据

2. 从JSP 页面传递参数给 Servlet

1)使用 request 对象接受参数

2)使用 session 对象,url,form表单传递参数

3. 从 Servlet 向 JSP 页面中传递参数

从 Servlet 到 JSP 页面传递参数,可以使用 URL,request 对象,session 对象

4. 从一个 Servlet 向另一个 Servlet 传递参数

1)通过超链接和 form 表单传递数据

2)使用 setAttribute() 和 getAttribute() 方法传递参数

https://blog.csdn.net/Qiuzhongweiwei/article/details/76037324

5. 将后台数据库中查询的结果传递到JSP页面中

查询数据库后获得的结果是 ResultSet

递归 ResultSet 获得相应数据,然后将这些数据再依次存入列表中,最后将存放数据的列表以属性的方式封装到 request 或者 session 中,这样在 JSP 页面中就可以读取属性

...
try {
if (resultSet == null) {
response.sendRedirect("/pathogen/queryPathogen");
return;
}
while (resultSet.next()) {
QueryResult queryResult = new QueryResult();
queryResult.setTaxid(resultSet.getString("taxid"));
queryResult.setOrganismName(resultSet.getString("organism_name")); // 物种名称
queryResult.setGramStrain(resultSet.getString("gram_strain")); // 革兰氏分型
queryResult.setSuperkingdom(resultSet.getString("superkingdom")); // 分类地位
queryResult.setDisease(resultSet.getString("disease")); // 疾病名称
queryResult.setIsolationSource(resultSet.getString("isolation_source")); // 样本来源
queryResult.setEvidenceSupport(resultSet.getString("evidence_support")); // 收录来源
queryResultList.add(queryResult); // 将每条记录追加到列表中
};
request.setAttribute("queryPathogenResultList", queryResultList); // 将查询结果封装到 request 范围的属性中
RequestDispatcher requestDispatcher = request.getRequestDispatcher("/JSP/queryPathogen.jsp");
requestDispatcher.forward(request, response); // 将 request 和 response 转发到相应的 JSP页面中
} catch (SQLException e) {
e.printStackTrace();
}

在 JSP 页面中读取封装到 request 中的数据

<%
if (request.getAttribute("queryPathogenResultList") != null ) {
%>
<div>
<h2>病原数据库检索结果</h2>
<%
if (((List<Object>)request.getAttribute("queryPathogenResultList")).isEmpty()) {
%>
未查询到结果!
<%
} else {
%>
<table border=1 >
<tr>
<c:if test="${requestScope.taxid == 'taxid' }" >
<th>taxId</th>
</c:if>
<c:if test="${requestScope.organismName == 'organismName' }" >
<th>物种名称</th>
</c:if>
<c:if test="${requestScope.gramStrain == 'gramStrain' }" >
<th>格兰氏分型</th>
</c:if>
<c:if test="${requestScope.rank == 'rank' }" >
<th>分类地位</th>
</c:if>
<c:if test="${requestScope.disease == 'disease' }" >
<th>疾病信息</th>
</c:if>
<c:if test="${requestScope.isolationSource == 'isolationSource' }" >
<th>样本来源</th>
</c:if>
<c:if test="${requestScope.dataSource == 'dataSource' }" >
<th>收录来源</th>
</c:if>
<c:if test="${requestScope.gcContent == 'gcContent' }" >
<th>GC含量</th>
</c:if>
<c:if test="${requestScope.refGenome == 'refGenome' }" >
<th>参考基因组</th>
</c:if>
</tr>
<c:forEach items="${queryPathogenResultList}" var="queryPathogenResult" >
<tr>
<c:if test="${requestScope.taxid == 'taxid' }" >
<td>${queryPathogenResult.taxid }</td>
</c:if>
<c:if test="${requestScope.organismName == 'organismName' }" >
<td>${queryPathogenResult.organismName }</td>
</c:if>
<c:if test="${requestScope.gramStrain == 'gramStrain' }" >
<td>${queryPathogenResult.gramStrain }</td>
</c:if>
<c:if test="${requestScope.rank == 'rank' }" >
<td>${queryPathogenResult.superkingdom }</td>
</c:if>
<c:if test="${requestScope.disease == 'disease'}" >
<td>${queryPathogenResult.disease }</td>
</c:if>
<c:if test="${requestScope.isolationSource == 'isolationSource' }" >
<td>${queryPathogenResult.isolationSource }</td>
</c:if>
<c:if test="${requestScope.dataSource == 'dataSource' }" >
<td>${queryPathogenResult.evidenceSupport }</td>
</c:if>
<c:if test="${requestScope.gcContent == 'gcContent' }" >
<td></td>
</c:if>
<c:if test="${requestScope.refGenome == 'refGenome' }" >
<td></td>
</c:if>
</tr>
</c:forEach>
</table>
<%
}
%>
</div>
<%
}
%>

最新文章

  1. Oracle碎碎念~2
  2. 按日期切割nginx访问日志--及性能优化
  3. 应用程序框架实战十三:DDD分层架构之我见
  4. Visual studio 非常好的插件
  5. sublime text2之js压缩-Js Minifier
  6. 教你用Java安全有效的实现两星期内自动登陆功能-Session
  7. [原博客] POJ 1740 A New Stone Game
  8. MongoDB简单操作
  9. 慕课linux学习笔记(六)常用命令(3)
  10. Swift - 创建并设置背景(SpriteKit游戏开发)
  11. twitter分享问题(四)—— Unknown error(api v1过度到V1.1产生)
  12. Python使用MySQLdb操作MySQL
  13. Python ---------copy
  14. kick_ball
  15. Sping--AOP--XML
  16. ajaxfileupload插件,C#返回Json数据报错
  17. 学习iOS最权威的网站
  18. WIn10系统软件默认安装c盘后消失看不见问题
  19. 转载:mybatis踩坑之——foreach循环嵌套if判断
  20. 这就是使用ReportBuilder最简单的例子

热门文章

  1. Linux环境安装、卸载Docker
  2. python-day7-静态方法、类方法、属性方法、特殊成员方法、反射、异常处理、socket
  3. abaqus2016安装过程中出现error:unable to add abaqus command directory to PATH variable
  4. SnowFlake学习
  5. UE4 多人网络对战游戏笔记
  6. fiddler抓https包
  7. 安卓出现错误: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
  8. find 递归/不递归 查找子目录的方法
  9. React Native的学习资源网址
  10. Python库 - Albumentations 图片数据增强库