简体   繁体   English

JSP从Servlet获取参数

[英]JSP getting parameters from servlet

I'm working on a Java web application and i want my JSP files to comunicate with my Servlets which comunicate with the database. 我正在使用Java Web应用程序,并且希望我的JSP文件与与数据库通信的Servlet通信。

What is the best way to pass entities i have created from a Servlet to a JSP page? 将我从Servlet创建的实体传递到JSP页面的最佳方法是什么?

The standard way to send information from a Servlet to a JSP is to put it in "request scope" using code like this: 将信息从Servlet发送到JSP的标准方法是使用如下代码将其放入“请求范围”:

List listOfUsers = myDAO.getUsers();    
request.setAttribute("users", listOfUsers);

In your JSP, you would retrieve the users object with something like: 在您的JSP中,您将使用以下内容检索users对象:

<c:forEach var="user" items="users">
User: <c:out value="${user}"/>
</c:forEach>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM